Home  >  Article  >  Backend Development  >  How to batch replace text information in php

How to batch replace text information in php

王林
王林Original
2020-11-03 09:47:173310browse

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

How to batch replace text information in php

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!

Statement:
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