How to replace multiple strings in php

王林
Release: 2023-03-03 14:54:02
Original
6009 people have browsed it

How to replace multiple strings in php: You can use the str_replace() function to replace. The specific usage method is: [str_replace($arr1,$arr2,$str)]. The str_replace() function replaces some characters in a string and returns a string or array with the replacement value.

How to replace multiple strings in php

Function introduction:

(Recommended tutorial:php graphic tutorial)

str_replace( ) function replaces some characters in a string (case-sensitive) and returns a string or array with the replacement values.

Usage rules:

  • If the searched string is an array, then it will return an array.

  • If the searched string is an array, then it will find and replace each element in the array.

  • If an array needs to be searched and replaced at the same time, and the elements to be replaced are less than the number of found elements, the excess elements will be replaced with empty strings .

  • If you search an array and replace only one string, the replacement string will work for all found values.

Function syntax:

str_replace(find,replace,string,count)
Copy after login

(Video tutorial recommendation:php video tutorial)

Parameter introduction:

  • find Required. Specifies the value to look for.

  • replace Required. Specifies the value to replace the value in find .

  • #string Required. Specifies the string to be searched for.

  • #count Optional. A variable counting the number of substitutions.

Code:

How to replace multiple strings in php

The above is the detailed content of How to replace multiple 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
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!