How to batch replace strings in php

coldplay.xixi
Release: 2023-03-06 12:40:01
Original
6250 people have browsed it

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;].

How to batch replace strings in php

php method to replace strings in batches:

str_replace Batch search and replace strings

<?php
$str = &#39;I Love You!&#39;;
$str = str_replace(&#39;o&#39;,&#39;O&#39;,$str,$count);
echo $str.PHP_EOL; // I LOve YOu!
echo &#39;替换了&#39;.$count.&#39;个&#39;.PHP_EOL; // 替换了2个
$str = &#39;I Love You!&#39;;
$str = str_replace([&#39;o&#39;,&#39;u&#39;],&#39;O&#39;,$str,$count);
echo $str.PHP_EOL; // I LOve YOO!
echo &#39;替换了&#39;.$count.&#39;个&#39;.PHP_EOL; // 替换了3个
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template