Home >Backend Development >PHP Problem >How to replace all specified characters in Php

How to replace all specified characters in Php

藏色散人
藏色散人Original
2021-09-24 09:18:433919browse

Php method to replace all specified characters: 1. Use the "str_replace(find,replace,string,count)" method to replace; 2. Use the "preg_replace()" method to replace.

How to replace all specified characters in Php

The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.

How to replace all specified characters in Php?

Commonly used functions are:

str_replace() and preg_replace().

str_replace() function uses a string to replace other characters in a string.

str_replace(find,replace,string,count)

Parameters

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.

str_replace("raykaeso", "leixuesong", "raykaeso love php");
preg_replace ( pattern , replacement , subject,limit = -1 ,$count )

Function: Perform a regular expression search and replace

pattern required. The pattern to search for.

replacement Required. String or array to use for replacement.

subject Required. String or array to be replaced.

limit the number of replacements. -1 is unlimited

count number of times to complete the substitution, variable

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to replace all specified characters 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