php常用字符串String函数实例总结【转换,替换,计算,截取,加密】
发布时间:2020-12-12 21:54:42 所属栏目:PHP教程 来源:网络整理
导读:本文实例总结了php常用字符串String函数。供大家参考研究具体如下: nl2br 功能:化换行符为 rtrim 功能:清除右边的空白 ";$result = rtrim($str);echo strlen($result);/**结果1411*/ strip_tags 功能:清除字符串中html和php的标记 Hello world "
本文实例总结了php常用字符串String函数。分享给大家供大家参考,具体如下: nl2br功能:化换行符为 rtrim功能:清除右边的空白 ";
$result = rtrim($str);
echo strlen($result);
/**结果
14
11
*/
strip_tags功能:清除字符串中html和php的标记 Hello world";
$result = strip_tags($str);
echo $result;
/**结果
Hello world
*/
strtolower 与 strtoupper功能:转换成大小写 ";
$result = strtoupper($str);
echo $result;
/**结果
hello world!
HELLO WORLD!
*/
trim功能:去除首尾空格 ";
echo $result."
"; echo strlen($str)." "; echo strlen($result); /**结果 Hello World! Hello World! 16 12 */ str_ireplace功能:替换 ";
echo $result;
/**结果
zhang san
li san
*/
str_repeat功能:将一个字符串重复多遍 ";
echo $result;
/**结果
Hello jiqing!
Hello jiqing!Hello jiqing!Hello jiqing!Hello jiqing!
*/
str_replace功能:区分大小写的替换 ";
echo $result1."
"; echo $result2." "; /**结果 hello jiqing! Hi jiqing! hello jiqing! */ str_word_count功能:返回字符串中单词的个数 ";
echo $result1."
"; print_r($result2); /**结果 hello jiqing a! 3 Array ( [0] => hello [1] => jiqing [2] => a ) */ strlen功能:返回字符串长度 substr_count功能:计算一个字符串在另一个字符串中的个数 substr_replace功能:从某个位置开始替换 ";
$result = substr_replace($str,6,6);//从某个位置替换,替换几个字符串
echo $result;
/**结果
hello zhangsan
hello zhangsan,hello jim!
*/
substr功能:获取子字符串 ";
$result = substr($str,-1);//从第0个开始,获取到除了最后一个的字符串
echo $result."
"; $result = substr($str,2,-1);//从第2个开始,获取到除了最后一个的字符串 echo $result." "; $result = substr($str,-3,-1);//从第-3个开始,获取到除了最后一个的字符串 echo $result." "; $result = substr($str,1);//从第-3个开始,获取到除了最后一个的字符串 echo $result." "; /**结果 a abcde cde de d */ implode功能:将数组转化为字符串 md5功能:对字符串进行md5加密 更多关于PHP相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》、《》、《》及《》 希望本文所述对大家PHP程序设计有所帮助。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |