【Day65】php常用字符串转换,替换,计算,截取,加密函数实例
来源:互联网 发布:变音软件ios 版本 编辑:程序博客网 时间:2024/05/22 05:34
nl2br
功能:化换行符为
<?php$str = "cat isn't \n dog";$result = nl2br($str);echo $result;/**结果cat isn'tdog*/
rtrim
功能:清除右边的空白
<?php$str = "Hello world ";echo strlen($str)."<br>";$result = rtrim($str);echo strlen($result);/**结果1411*/
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!1612*/
str_ireplace
功能:替换
<?php$str = "zhang san";$result = str_ireplace("zhang","li",$str);echo $str."<br>";echo $result;/**结果zhang sanli 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!3Array ( [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 zhangsanhello 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>";/**结果aabcdecdeded*/
implode
功能:将数组转化为字符串
<?php$array = array("2016","6","3");$date = implode("/",$array);echo $date;/**结果2016/6/3*/
md5
功能:对字符串进行md5加密
<?php$str = "Hello world";$result = md5($str);echo $result;/**结果3e25960a79dbc69b674cd4ec67a72c62*/
0 0
- 【Day65】php常用字符串转换,替换,计算,截取,加密函数实例
- php中常用的字符串截取函数mb_substr实例解释
- php字符串处理函数 字符串查找、替换、截取
- php中常用的字符串大小写转换函数实例解释
- 截取字符串 替换字符串 函数
- Android 字符串截取替换函数
- PHP 字符串截取函数
- PHP 截取字符串函数
- php 字符串截取函数
- php截取字符串函数
- php 字符串截取函数
- php 字符串截取函数
- php字符串截取函数
- php字符串截取函数
- php字符串截取函数
- php字符串函数(1)长度计算、查找、截取
- 字符串进行截取替换操作实例代码
- php字符串替换函数
- POJ 2823 Sliding Window 已翻译
- 【LaTeX】WinEdt编辑UTF-8中文文档出现乱码或编译错误"Package CJK Error: Invalid character code"的解决方案
- 白帽子讲web安全之3
- Spring4的知识应用总结(三)——Bean之间的关系和作用域
- POJ 3260 The Fewest Coins 已翻译
- 【Day65】php常用字符串转换,替换,计算,截取,加密函数实例
- 方法数超过64K:The number of method references in a .dex file cannot exceed 64K.
- [J2EE]jsp项目中使用UEditor富文本编辑器
- opencv学习笔记(七)从电脑摄像头读入数据
- Retry重试机制
- c# datagridview 使用大全
- 互联网支付-退款中多证书情况下串证书Id
- leetcode--Binary Tree Paths
- 【opencv 官方教程】翻译2 核心功能 上