插件4:删除空格

来源:互联网 发布:地理信息大数据 编辑:程序博客网 时间:2024/04/30 21:56
<?php // Plug-in 4: Strip Whitespace// This is an executable example with additional code supplied// To obtain just the plug-ins please click on the Download link$text = "      We hold   these truths to be self-evident,       that all men are created equal, that they are endowed by their Creator with certain unalienable     Rights, that among these are Life, Liberty and     the pursuit of Happiness. ?That to secure these rights, \n\n \tGovernments are     instituted among Men, deriving their just powers from the consent of the governed, ?That whenever any      Form of Government becomes destructive \n \t of these ends, it is the    Right of the People to alter or to abolish it, and to institute new Government, laying its foundation on such principles and      organizing its powers in such form, as to them shall seem most likely to effect their Safety and Happiness.    ";echo "<textarea cols='68' rows='11'>$text</textarea><br />";echo PIPHP_StripWhitespace($text);function PIPHP_StripWhitespace($text){   // Plug-in 4: Strip Whitespace   //   // This plug-in takes a string variable containing any   // text and then strips out all whitespace characters.   // The arguments rquired are:   //   //    $text: Text to be modified    return preg_replace('/\s+/', ' ', $text);}?>

1. 插件说明

这个插件接受一个包包含任何文本的字符串参数,将去掉全部多余空格。它需要一个参数:

$text——字符串变量,包含需要处理的文本。

原创粉丝点击