How to replace multiple characters at the same time with php str_replace

青灯夜游
Release: 2023-03-15 20:02:01
Original
4642 people have browsed it

Method: Set the first parameter of str_replace() to an array, the syntax "str_replace(array,'replacement value',$str)" can replace multiple characters with the same specified character; If you want to replace it with a different specified character, you only need to set the second parameter to an array, and the number of elements in the two arrays must be the same.

How to replace multiple characters at the same time with php str_replace

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php str_replace simultaneously replace Multiple characters

str_replace() Replaces a specific string specified in the original string with a new string.

str_replace(find,replace,string,count)
Copy after login
Parameters Description
find Required . Specifies the value to look for.
replace Required. Specifies a value that replaces the value infind.
string Required. Specifies the string to be searched for.
count Optional. A variable counting the number of substitutions.

Generally, the str_replace() function only searches for one value and replaces it with the specified value.

"; ?>
Copy after login

How to replace multiple characters at the same time with php str_replace

When the first parameterfindof the function is set to an array type, multiple values can be searched:

"; ?>
Copy after login

How to replace multiple characters at the same time with php str_replace

This is to replace multiple characters with the same specified character. If the second parameter replace of the function is also set to an array type, it can be replaced with different specified characters

- b->! c->~ echo $newStr."
"; ?>
Copy after login

How to replace multiple characters at the same time with php str_replace

#Note: At this time, the number of elements in the two arrays must be the same.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to replace multiple characters at the same time with php str_replace. 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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!