下拉列表框中的值怎么取的
下拉列表框中的值怎么取的
作者 babee 发布于 0000-00-00 分类:php基础编程
用trim,chop,ltrim这三个函数都试了,能把头尾的连续空白去了,但字符串中的连续空白去不掉。比如:
字符串“a b”两字母中间有10空格,用了上述函数后,计算一下字符串的长度,还是12,如何能把字符串中间的连续空白变为一个呢?我不要求全部去掉
逛论坛交流:关于去除字符串中连续空白的问题
>$str="a b c";
$astr=split(" ",$str);
for($i=0;$i
$s.=$astr[$i]." ";
}
echo $s;
>ltrim
去除连续空白。
语法: string ltrim(string str);
返回值: 字符串
函数种类: 资料处理
内容说明
本函数用来删去字符串中的连续空白带 (whitespace)。
>楼上的看得懂英文吧?什么叫beginning of a string? 什么叫字符串中的连续空白带?不要搞笑哦。
ltrim Strip whitespace from the beginning of a string
usage: string ltrim ( string str [, string charlist] )
available since: PHP 3, PHP 4
Note:
The second parameter was added in PHP 4.1.0
This function returns a string with whitespace stripped from the beginning of str. Without the second parameter, ltrim() will strip these characters:
" " (ASCII 32 (0x20)), an ordinary space.
" " (ASCII 9 (0x09)), a tab.
"
" (ASCII 10 (0x0A)), a new line (line feed).
"
" (ASCII 13 (0x0D)), a carriage return.
" " (ASCII 0 (0x00)), the NUL-byte.
"x0B" (ASCII 11 (0x0B)), a vertical tab.
You can also specify the characters you want to strip, by means of the charlist parameter. Simply list all characters that you want to be stripped. With .. you can specify a range of characters.
>反正我知道chop是不行的,至于trim是去除前后字符空白的。
不过discuz好像做到了。我再试试这个论坛 g
>用正则
>用regex
$patern="/( .+)";
preg_replace($patern,,$string);
即可。试试吧。
6 条回复
回复