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
*/

最新文章

  1. haproxy 新手上路
  2. SQL server 动态行转列
  3. POJ3468A Simple Problem with Integers(区间加数求和 + 线段树)
  4. plink远程连接服务器进行编译
  5. ubuntu安装shadowshocks-qt5
  6. java 开发常用的Linux命令
  7. 【读书笔记】iOS-UIFont-动态下载系统提供的字体-官方代码
  8. hadoop完全分布式安装(转)
  9. 黑信 socket即时通讯 示例
  10. Codeforces 85D Sum of Medians(线段树)
  11. VMware vSphere服务器虚拟化实验十五 vCenter vShield Manager
  12. 拆分字段优化SQL
  13. 我是这么配置mariadb的。 为了能够操作汉字数据~
  14. vue--简化项目逻辑属性
  15. POI 导入excel 代码记录 方便以后粘贴
  16. 动态分配内存 new
  17. BZOJ4997 [Usaco2017 Feb]Why Did the Cow Cross the Road III
  18. VBA 根据Find方法根据特定内容查找单元格
  19. jQuery 表单内容的获取
  20. CTags配好后仍找不到函数定义的问题

热门文章

  1. 为PyCharm配置QT
  2. KDevelop4调试pcl一直读取不到.pcd文件
  3. (原创)D-query SPOJ - DQUERY(莫队)统计不同数的数量
  4. ThinkPHP CURD 操作
  5. 【bzoj4939】【YNOI2016】掉进兔子洞(莫队)
  6. SpringBoot Junit测试Controller
  7. loj#6229 这是一道简单的数学题
  8. Reincarnation HDU - 4622
  9. 牛客国庆集训day5 B 电音之王 (大数乘模)
  10. Rhino-- JavaScript