php常用字符串String函数实例总结【转换,替换,计算,截取,加密】
2016-12-07 00:00
871 查看
本文实例总结了php常用字符串String函数。分享给大家供大家参考,具体如下:
nl2br
功能:化换行符为<br>
rtrim
功能:清除右边的空白
strip_tags
功能:清除字符串中html和php的标记
strtolower 与 strtoupper
功能:转换成大小写
trim
功能:去除首尾空格
str_ireplace
功能:替换
str_repeat
功能:将一个字符串重复多遍
str_replace
功能:区分大小写的替换
str_word_count
功能:返回字符串中单词的个数
strlen
功能:返回字符串长度
substr_count
功能:计算一个字符串在另一个字符串中的个数
substr_replace
功能:从某个位置开始替换
substr
功能:获取子字符串
implode
功能:将数组转化为字符串
md5
功能:对字符串进行md5加密
更多关于PHP相关内容感兴趣的读者可查看本站专题:《php字符串(string)用法总结》、《PHP数组(Array)操作技巧大全》、《PHP基本语法入门教程》、《PHP运算与运算符用法总结》、《php面向对象程序设计入门教程》、《PHP网络编程技巧总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。
php strstr查找字符串中是否包含某些字符的查找函数
PHP 查找字符串常用函数介绍
php中利用explode函数分割字符串到数组
Thinkphp模板中截取字符串函数简介
PHP反转字符串函数strrev()函数的用法
PHP开发中常用的字符串操作函数
php字符串分割函数explode的实例代码
php 常用字符串函数总结
解析php获取字符串的编码格式的方法(函数)
PHP中常用的字符串格式化函数总结
PHP产生随机字符串函数
nl2br
功能:化换行符为<br>
<?php $str = "cat isn't \n dog"; $result = nl2br($str); echo $result; /**结果 cat isn't dog */
rtrim
功能:清除右边的空白
<?php $str = "Hello world "; echo strlen($str)."<br>"; $result = rtrim($str); echo strlen($result); /**结果 14 11 */
strip_tags
功能:清除字符串中html和php的标记
<?php $str = "<font color = 'red'>Hello world</font>"; $result = strip_tags($str); echo $result; /**结果 Hello world */
strtolower 与 strtoupper
功能:转换成大小写
<?php $str = "Hello World!"; $result = strtolower($str); echo $result."<br>"; $result = strtoupper($str); echo $result; /**结果 hello world! HELLO WORLD! */
trim
功能:去除首尾空格
<?php $str = " Hello World! "; $result = trim($str); echo $str."<br>"; echo $result."<br>"; echo strlen($str)."<br>"; echo strlen($result); /**结果 Hello World! Hello World! 16 12 */
str_ireplace
功能:替换
<?php $str = "zhang san"; $result = str_ireplace("zhang","li",$str); echo $str."<br>"; echo $result; /**结果 zhang san li san */
str_repeat
功能:将一个字符串重复多遍
<?php $str = "Hello jiqing!"; $result = str_repeat($str,4); echo $str."<br>"; echo $result; /**结果 Hello jiqing! Hello jiqing!Hello jiqing!Hello jiqing!Hello jiqing! */
str_replace
功能:区分大小写的替换
<?php $str = "hello jiqing!"; $result1 = str_ireplace("Hello","Hi",$str); //不区分大小写 $result2 = str_replace("Hello","Hi",$str); //区分大小写 echo $str."<br>"; echo $result1."<br>"; echo $result2."<br>"; /**结果 hello jiqing! Hi jiqing! hello jiqing! */
str_word_count
功能:返回字符串中单词的个数
<?php $str = "hello jiqing a!"; $result1 = str_word_count($str); //返回个数 $result2 = str_word_count($str,1); //返回数组 echo $str."<br>"; echo $result1."<br>"; print_r($result2); /**结果 hello jiqing a! 3 Array ( [0] => hello [1] => jiqing [2] => a ) */
strlen
功能:返回字符串长度
<?php $str = "hello jiqing a!"; $result = strlen($str); echo $result; /**结果 15 */
substr_count
功能:计算一个字符串在另一个字符串中的个数
<?php $str = "hello jiqing ,hello jim!"; $result = substr_count($str,"hello"); echo $result; /**结果 2 */
substr_replace
功能:从某个位置开始替换
<?php $str = "hello jiqing ,hello jim!"; $result = substr_replace($str,"zhangsan",6); echo $result."<br>"; $result = substr_replace($str,"zhangsan",6,6);//从某个位置替换,替换几个字符串 echo $result; /**结果 hello zhangsan hello zhangsan ,hello jim! */
substr
功能:获取子字符串
<?php $str = "abcdef"; $result = substr($str,0,1); //从第0个开始,获取1个 echo $result."<br>"; $result = substr($str,0,-1);//从第0个开始,获取到除了最后一个的字符串 echo $result."<br>"; $result = substr($str,2,-1);//从第2个开始,获取到除了最后一个的字符串 echo $result."<br>"; $result = substr($str,-3,-1);//从第-3个开始,获取到除了最后一个的字符串 echo $result."<br>"; $result = substr($str,-3,1);//从第-3个开始,获取到除了最后一个的字符串 echo $result."<br>"; /**结果 a abcde cde de d */
implode
功能:将数组转化为字符串
<?php $array = array("2013","6","3"); $date = implode("/",$array); echo $date; /**结果 2013/6/3 */
md5
功能:对字符串进行md5加密
<?php $str = "Hello world"; $result = md5($str); echo $result; /**结果 3e25960a79dbc69b674cd4ec67a72c62 */
更多关于PHP相关内容感兴趣的读者可查看本站专题:《php字符串(string)用法总结》、《PHP数组(Array)操作技巧大全》、《PHP基本语法入门教程》、《PHP运算与运算符用法总结》、《php面向对象程序设计入门教程》、《PHP网络编程技巧总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。
您可能感兴趣的文章:
PHP字符转义相关函数小结(php下的转义字符串)php strstr查找字符串中是否包含某些字符的查找函数
PHP 查找字符串常用函数介绍
php中利用explode函数分割字符串到数组
Thinkphp模板中截取字符串函数简介
PHP反转字符串函数strrev()函数的用法
PHP开发中常用的字符串操作函数
php字符串分割函数explode的实例代码
php 常用字符串函数总结
解析php获取字符串的编码格式的方法(函数)
PHP中常用的字符串格式化函数总结
PHP产生随机字符串函数
相关文章推荐
- php常用字符串String函数实例总结【转换,替换,计算,截取,加密】
- PHP入门教程之字符串处理技巧总结(转换,过滤,解析,查找,截取,替换等)
- PHP入门教程之字符串处理技巧总结(转换,过滤,解析,查找,截取,替换等)
- PHP常用字符串操作函数实例总结(trim、nl2br、addcslashes、uudecode、md5等)
- php中文字符串截取方法实例总结
- php中常用的字符串截取函数mb_substr实例解释
- 生成二维码 加密解密类 TABLE转换成实体、TABLE转换成实体集合(可转换成对象和值类型) COOKIE帮助类 数据类型转换 截取字符串 根据IP获取地点 生成随机字符 UNIX时间转换为DATETIME\DATETIME转换为UNIXTIME 是否包含中文 生成秘钥方式之一 计算某一年 某一周 的起始时间和结束时间
- 黄聪:PHP字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、切割成数组等)
- php中常用的字符串截取函数mb_substr实例解释
- php常用数组array函数实例总结【赋值,拆分,合并,计算,添加,删除,查询,判断,排序】
- php中文字符串截取方法实例总结
- Python 字符串(三)-字符串操作实例(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- php常用数组array函数实例总结【赋值,拆分,合并,计算,添加,删除,查询,判断,排序】
- PHP常用字符串操作函数实例总结(trim、nl2br、addcslashes、uudecode、md5等)
- php中文字符串截取方法实例总结
- PHP常用字符串操作函数实例总结(trim、nl2br、addcslashes、uudecode、md5等)
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- PHP常用字符串总结(待续)
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)