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

How to batch replace text information in php

王林
Release: 2023-03-06 22:58:02
Original
3336 people have browsed it

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";
Copy after login

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
**/
Copy after login

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!

Related labels:
php
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