首頁  >  文章  >  後端開發  >  php中字串與字元替換用什麼函數

php中字串與字元替換用什麼函數

王林
王林原創
2020-07-31 14:21:172906瀏覽

php中字串與字元替換用str_replace()函數。 str_replace()函數取代字串中的一些字元(區分大小寫),函數語法為:【str_replace(find,replace,string,count)】。

php中字串與字元替換用什麼函數

str_replace() 函數取代字串中的一些字元(區分大小寫)。

(推薦教學:php圖文教學

函數語法:

str_replace(find,replace,string,count)

(影片教學推薦:php視頻教學

參數說明:

  • find    必要。規定要找的值。   

  • replace    必需。規定替換 find 中的值的值。   

  • string    必需。規定被搜尋的字串。   

  • count    可選。一個變量,對替換數進行計數。   

程式碼範例:

<?php
$arr = array("blue","red","green","yellow");
print_r(str_replace("red","pink",$arr,$i));
echo "Replacements: $i";
?>

以上是php中字串與字元替換用什麼函數的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn