Home > Article > Backend Development > How to batch replace strings in php
php method to replace strings in batches: use [str_replace] to find and replace strings in batches, the code is [$str = str_replace('o','O',$str,$count);echo $str .PHP_EOL;].
php method to replace strings in batches:
str_replace Batch search and replace strings
<?php $str = 'I Love You!'; $str = str_replace('o','O',$str,$count); echo $str.PHP_EOL; // I LOve YOu! echo '替换了'.$count.'个'.PHP_EOL; // 替换了2个 $str = 'I Love You!'; $str = str_replace(['o','u'],'O',$str,$count); echo $str.PHP_EOL; // I LOve YOO! echo '替换了'.$count.'个'.PHP_EOL; // 替换了3个
Related free learning recommendations: php programming (video)
The above is the detailed content of How to batch replace strings in php. For more information, please follow other related articles on the PHP Chinese website!