php method to replace text information in batches: You can choose to use the str_replace() function to perform batch replacement operations, such as [$arr = array("blue","red","green"); str_replace("red ","pink",$arr,$i)].
Use the function:
str_replace() function replaces some characters in the string (case-sensitive), returns with A string or array of replacement values.
(Recommended tutorial: php video tutorial)
Common methods:
$arr = array("blue","red","green","yellow"); print_r(str_replace("red","pink",$arr,$i)); echo "替换数:$i";
Advanced usage
$find = array("Hello","world"); $replace = array("B","A"); $arr = array("Hello world","world","!"); $str = "Hello world danbus world"; print_r(str_replace($find,$replace,$arr)); print_r(str_replace($find,$replace,$str)); /** Array ( [0] => B A [1] => A [2] => ! ) ------------------- B A danbus A **/
Related recommendations : php training
The above is the detailed content of How to batch replace text information in php. For more information, please follow other related articles on the PHP Chinese website!