首页  >  文章  >  php教程  >  php 字符串处理函数大全教程

php 字符串处理函数大全教程

WBOY
WBOY原创
2016-06-08 17:26:201081浏览
<script>ec(2);</script>

//截取字符串
mb_substr($str,star,count,encode);
//获取字符串长度
mb_strlen();
//完整保留在textarea文本中的回车换行
str_replace(chr(10),"
",$textarea);


//根据ascii返回相应的字母
echo "ascii为66的字母是:". chr(66)."
";

//chop 去除字符串中的连续空格和空白
$str="         he llo wo rd     ";echo "s:";
echo "s:".chop($str)."w";

//explode 按照某个字符分割字符串 返回数组
$str="green,red,yellow,white";
$arr=explode(" ",$str);echo "分割后的数组是:";
print_r($arr);

//implode 将数组按照某个字符拼成字符串
$arr=array("a","b","c","d");
$str=implode('/',$arr);
echo "
拼成的字符串是:".$str;

//打印print
print("打印的方法print");
echo "格式化打印printf:
";
printf("%f%",2,"d");

//不区分大小写比较字符串
echo "不区分大小写:".strcasecmp("hello word","hello word");
//区分大小写
echo "区分大小写:". strcmp("hello word","hello word");

//查找字符串
echo "查找的结果是:". strchr("hello word","hello");
//字符串长度
echo "str长度:".strlen("hello word");

//将字符串重复几次str_repeat
echo "将字符串重复几次:".str_repeat("ws",3);

//将字符串倒序排列
echo "zifuchuandaoxu:".strrev("zifuchuandaoxu");

//将字符串大写,小写转化
//strtolower();
//strtoupper();
//字符串替换,
echo "替换后的字符串是:". str_replace("b","*","aaaaabbbbbccccc");
//切割字符串
echo "切割后的字符串是:". substr("hello word",2,3);

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn