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字符串函数详解的更多相关文章

  1. python pandas字符串函数详解(转)

     pandas字符串函数详解(转)——原文连接见文章末尾 在使用pandas框架的DataFrame的过程中,如果需要处理一些字符串的特性,例如判断某列是否包含一些关键字,某列的字符长度是否小于3等等 ...

  2. oracle中的字符串函数详解

    花了点时间 复习.了一下字符串函数 希望对初学者有帮助 ----------连接字符串函数-----------------select concat('leiyi','hubei') from du ...

  3. Mysql 字符串函数 详解

    字符串函数是最常用的一种函数了,如果大家编写过程序的话,不妨回过头去看看自己使用过的函数,可能会惊讶地发现字符串处理的相关函数占已使用过的函数很大一部分.MySQL中字符串函数也是最丰富的一类函数,表 ...

  4. 使用JS截取字符串函数详解

    一.函数:split() 功能:使用一个指定的分隔符把一个字符串分割存储到数组 例子: str=”jpg|bmp|gif|ico|png”; arr=theString.split(”|”); //a ...

  5. C++ string 字符串函数详解

    运算符重载 + 和 +=:连接字符串 =:字符串赋值 >.>=.< 和 <=:字符串比较(例如a < b, aa < ab) ==.!=:比较字符串 << ...

  6. c语言字符串函数详解

    转载请注明来源:https://www.cnblogs.com/hookjc/ oid *memset(void *dest, int c, size_t count); 将dest前面count个字 ...

  7. NSSearchPathForDirectoriesInDomains函数详解

    NSSearchPathForDirectoriesInDomains函数详解     #import "NSString+FilePath.h" @implementation ...

  8. jquery $.trim()去除字符串空格详解

    jquery $.trim()去除字符串空格详解 语法 jQuery.trim()函数用于去除字符串两端的空白字符. 作用 该函数可以去除字符串开始和末尾两端的空白字符(直到遇到第一个非空白字符串为止 ...

  9. JavaScript正则表达式详解(二)JavaScript中正则表达式函数详解

    二.JavaScript中正则表达式函数详解(exec, test, match, replace, search, split) 1.使用正则表达式的方法去匹配查找字符串 1.1. exec方法详解 ...

随机推荐

  1. MongoDB 分片1

    第一步: 准备数据节点 必须添加–shardsvr参数. mongod--port32770--shardsvr--dbpathD:\db\mongodata\shard\mongodb1--logp ...

  2. C#之重载

    前言 今天去看了看论坛,发现有些人对于重载还是很有疑问的,像大多数人一样,貌似知道重载方法这回事儿, 但是具体怎么应用,或者用重载方法的好处,好像还是一知半解,模模糊糊.我们都知道,重载方法的定义,甚 ...

  3. Java—多线程实现PV效果

    前言 还记得今年参加自学操作系统考试,最难分析的就是PV这部分,然而伟大的米老师却用一个放东西吃东西的小例子,把PV讲的栩栩如生,言简意赅.学J2SE时学到了线程部分,里面提到了线程同步,死锁问题等等 ...

  4. loj #6077. 「2017 山东一轮集训 Day7」逆序对

    #6077. 「2017 山东一轮集训 Day7」逆序对   题目描述 给定 n,k n, kn,k,请求出长度为 n nn 的逆序对数恰好为 k kk 的排列的个数.答案对 109+7 10 ^ 9 ...

  5. t-sql read xlsx

    How to Read and Load an Excel 2007 or Excel 2010 File Without Using Import/Export Utility To read an ...

  6. 7、OpenCV Python 高斯模糊

    __author__ = "WSX" import cv2 as cv import numpy as np #高斯模糊 基于权重(卷积) #高斯模糊 去燥效果很好 #高斯模糊 d ...

  7. 【洛谷2324】[SCOI2005]骑士精神 IDA*

    [SCOI2005]骑士精神 描述 在一个\(5×5\)的棋盘上有\(12\)个白色的骑士和\(12\)个黑色的骑士, 且有一个空位.在任何时候一个骑士都能按照骑 士的走法(它可以走到和它横坐标相差为 ...

  8. html5 语音识别 转

  9. 关于thinkphp5中数据库分组查询group

    在使用tp5的group进行分组查询总是报错,以主键进行分组是不报错,但没有任何意义 与聚合函数一起使用的不会报错,如官方文档给出的代码 Db::table('think_user') ->fi ...

  10. spring cloud 超时时间

    zuul.host.socket-timeout-millis=60000 #zuul socket连接超时zuul.host.connect-timeout-millis=60000 #zull 请 ...