国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

php常用字符串String函數(shù)實例總結(jié)【轉(zhuǎn)換,替換,計算,截取,加密】

2024-05-04 23:53:20
字體:
供稿:網(wǎng)友

本文實例總結(jié)了php常用字符串String函數(shù)。分享給大家供大家參考,具體如下:

nl2br

功能:化換行符為<br>

<?php$str = "cat isn't /n dog";$result = nl2br($str);echo $result;/**結(jié)果cat isn'tdog*/

rtrim

功能:清除右邊的空白

<?php$str = "Hello world ";echo strlen($str)."<br>";$result = rtrim($str);echo strlen($result);/**結(jié)果1411*/

strip_tags

功能:清除字符串中html和php的標記

<?php$str = "<font color = 'red'>Hello world</font>";$result = strip_tags($str);echo $result;/**結(jié)果Hello world*/

strtolower 與 strtoupper

功能:轉(zhuǎn)換成大小寫

<?php$str = "Hello World!";$result = strtolower($str);echo $result."<br>";$result = strtoupper($str);echo $result;/**結(jié)果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);/**結(jié)果Hello World!Hello World!1612*/

str_ireplace

功能:替換

<?php$str = "zhang san";$result = str_ireplace("zhang","li",$str);echo $str."<br>";echo $result;/**結(jié)果zhang sanli san*/

str_repeat

功能:將一個字符串重復多遍

<?php$str = "Hello jiqing!";$result = str_repeat($str,4);echo $str."<br>";echo $result;/**結(jié)果Hello jiqing!Hello jiqing!Hello jiqing!Hello jiqing!Hello jiqing!*/

str_replace

功能:區(qū)分大小寫的替換

<?php$str = "hello jiqing!";$result1 = str_ireplace("Hello","Hi",$str); //不區(qū)分大小寫$result2 = str_replace("Hello","Hi",$str); //區(qū)分大小寫echo $str."<br>";echo $result1."<br>";echo $result2."<br>";/**結(jié)果hello jiqing!Hi jiqing!hello jiqing!*/

str_word_count

功能:返回字符串中單詞的個數(shù)

<?php$str = "hello jiqing a!";$result1 = str_word_count($str); //返回個數(shù)$result2 = str_word_count($str,1); //返回數(shù)組echo $str."<br>";echo $result1."<br>";print_r($result2);/**結(jié)果hello jiqing a!3Array ( [0] => hello [1] => jiqing [2] => a )*/

strlen

功能:返回字符串長度

<?php$str = "hello jiqing a!";$result = strlen($str);echo $result;/**結(jié)果15*/

substr_count

功能:計算一個字符串在另一個字符串中的個數(shù)

<?php$str = "hello jiqing ,hello jim!";$result = substr_count($str,"hello");echo $result;/**結(jié)果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;/**結(jié)果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>";/**結(jié)果aabcdecdeded*/

implode

功能:將數(shù)組轉(zhuǎn)化為字符串

<?php$array = array("2013","6","3");$date = implode("/",$array);echo $date;/**結(jié)果2013/6/3*/

md5

功能:對字符串進行md5加密

<?php$str = "Hello world";$result = md5($str);echo $result;/**結(jié)果3e25960a79dbc69b674cd4ec67a72c62*/

希望本文所述對大家PHP程序設計有所幫助。


注:相關教程知識閱讀請移步到PHP教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 黄平县| 宁河县| 定南县| 齐齐哈尔市| 阿拉善右旗| 徐汇区| 宣恩县| 平南县| 巴楚县| 连州市| 凤城市| 天等县| 隆安县| 京山县| 应城市| 寻乌县| 乌鲁木齐市| 黔西| 抚顺市| 屯留县| 富顺县| 红河县| 社旗县| 观塘区| 东辽县| 南丰县| 南漳县| 泰顺县| 辽中县| 五指山市| 玉山县| 乌兰浩特市| 寿阳县| 秭归县| 贡山| 金堂县| 鹤岗市| 普宁市| 临湘市| 枣庄市| 太和县|