strtoupper(string) 把字符串转换为大写。该函数是二进制安全的。
strtolower(string) 把字符串转换为小写。该函数是二进制安全的。
ucwords(string) 把字符串中每个单词的首字符转换为大写。该函数是二进制安全的。
ucfirst(string) 把字符串中的首字符转换为大写。该函数是二进制安全的。
lcfirst(string) 把字符串中的首字符转换为小写。该函数是二进制安全的。
string | 必需。规定要转换的字符串。 |
echo strtoupper("Hello WORLD.");//HELLO WORLD.echo strtolower("Hello WORLD.");//hello world.echo ucwords("hello world!");//Hello World!echo ucfirst("hello world!");//Hello world!echo lcfirst("Hello world!");//hello world!
substr(string,start,length) 返回字符串的一部分。
string | 必需。规定要返回其中一部分的字符串。 |
start | 必需。规定在字符串的何处开始。
|
length | 可选。规定被返回字符串的长度。默认是直到字符串的结尾。
|
注释:如果 start 参数是负数且 length 小于或等于 start,则 length 为 0。
echo substr("Hello world",6);//worldecho substr("Hello world",0,-1)."";//Hello worl
substr_replace(string,replacement,start,length) 把字符串的一部分替换为另一个字符串。
string | 必需。规定要检查的字符串。 |
replacement | 必需。规定要插入的字符串。 |
start | 必需。规定在字符串的何处开始替换。
|
length | 可选。规定要替换多少个字符。默认是与字符串长度相同。
|
注释:如果 start 参数是负数且 length 小于或者等于 start,则 length 为 0。
注释:该函数是二进制安全的。
echo substr_replace("Hello","world",0);//worldecho substr_replace("Hello world","Shanghai",6);//Hello Shanghaiecho substr_replace("Hello world","Shanghai",-5);//Hello Shanghaiecho substr_replace("world","Hello ",0,0);//Hello world$replace = array("1: AAA","2: AAA","3: AAA");echo implode(" ",substr_replace($replace,'BBB',3,3));//1: BBB 2: BBB 3: BBB
nl2br(string,xhtml)
string | 必需。规定要检查的字符串。 |
xhtml | 可选。布尔值,表示是否使用兼容 XHTML 换行:
|
在字符串中的每个新行(\n)之前插入 HTML 换行符(<br> 或 <br />)
echo nl2br("One line.\nAnother line.");//One line.//Another line.
explode(separator,string,limit) 把字符串打散为数组。
separator | 必需。规定在哪里分割字符串。 |
string | 必需。要分割的字符串。 |
limit | 可选。规定所返回的数组元素的数目。 可能的值:
|
"separator" 参数不能是空字符串。该函数是二进制安全的。
implode() 返回由数组元素组合成的字符串。