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

How to replace all specified characters in Php

藏色散人
Release: 2023-03-12 21:26:01
Original
3948 people have browsed it

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)
Copy after login

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");
Copy after login
preg_replace ( pattern , replacement , subject,limit = -1 ,$count )
Copy after login

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!

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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template