php 字串處理函數大全教程

來源:互聯網
上載者:User

//截取字串
mb_substr($str,star,count,encode);
//擷取字串長度
mb_strlen();
//完整保留在textarea文本中的斷行符號換行
str_replace(chr(10),"<br />",$textarea);


//根據ascii返回相應的字母
echo "ascii為66的字母是:". chr(66)."<br>";

//chop 去除字串中的連續空格和空白
$str="         he llo wo rd     ";echo "s:";
echo "s:".chop($str)."w";

//explode 按照某個字元分割字串 返回數組
$str="green,red,yellow,white";
$arr=explode(" ",$str);echo "分割後的數組是:";
print_r($arr);

//implode 將數組按照某個字元拼成字串
$arr=array("a","b","c","d");
$str=implode('/',$arr);
echo "<br>拼成的字串是:".$str;

//列印print
print("列印的方法print");
echo "格式化列印printf:<br>";
printf("%f%",2,"d");

//不區分大小寫比較字串
echo "不區分大小寫:".strcasecmp("hello word","hello word");
//區分大小寫
echo "區分大小寫:". strcmp("hello word","hello word");

//尋找字串
echo "尋找的結果是:". strchr("hello word","hello");
//字串長度
echo "str長度:".strlen("hello word");

//將字串重複幾次str_repeat
echo "將字串重複幾次:".str_repeat("ws",3);

//將字串倒序排列
echo "zifuchuandaoxu:".strrev("zifuchuandaoxu");

//將字串大寫,小寫轉化
//strtolower();
//strtoupper();
//字串替換,
echo "替換後的字串是:". str_replace("b","*","aaaaabbbbbccccc");
//切割字串
echo "切割後的字串是:". substr("hello word",2,3);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.