首页 > 代码库 > php 字符串重要函数
php 字符串重要函数
1、chop()
从字符串右端移除字符
chop(string,charlist)
$str="hello world~"; echo chop($str,"ld~"); //hello wor
ps. charlist参数是可选的,如果不填,默认移除
- "\0" - NULL
- "\t" - 制表符
- "\n" - 换行
- "\x0B" - 垂直制表符
- "\r" - 回车
- " " - 空格
2、chunk_split()
把字符串分割为一连串更小的部分。
chunk_split(string,length,end)
$str="hello world~"; echo chunk_split($str,1,"."); //h.e.l.l.o. .w.o.r.l.d.~.
3、explode()
把字符串打散为数组。
explode(separator,string,limit)
$str="beijing,shanghai,nanjing,tianjing,anqing"; print_r(explode(",",$str,3)); //Array ( [0] => beijing [1] => shanghai [2] => nanjing,tianjing,anqing )
ps. limit可选,规定所返回的数组元素的数目。
4、htmlspecialchars()
把预定义的字符转换为 HTML 实体。
htmlspecialchars(string,flags,character-set,double_encode)
$str="hello <em>world</em>~"; echo htmlspecialchars($str); //hello <em>world</em>~
- & (和号)成为 &
- " (双引号)成为 "
- ‘ (单引号)成为 ‘
- < (小于)成为 <
- > (大于)成为 >
5、implode() //别名为join()
返回由数组元素组合成的字符串。
implode(separator,array)
$arr=array("shanghai,nanjing,beijing,tianjing,anqing"); echo implode(" ",$arr); //shanghai,nanjing,beijing,tianjing,anqing
ps. separator可选。规定数组元素之间放置的内容。默认是 ""(空字符串)。
6、lcfirst()
把字符串中的首字符转换为小写。
lcfirst(string)
$arr="Hello world"; echo lcfirst($arr); //hello world
php 字符串重要函数
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。