How to perform string replacement in php

王林
Release: 2023-03-06 18:24:02
Original
2133 people have browsed it

How to replace string in php: You can use str_replace() function to replace, such as [str_replace("iwind", "kiki", "i love iwind, iwind said");].

How to perform string replacement in php

String replacement

(Recommended tutorial:php video tutorial)

str_replace("iwind", "kiki", "i love iwind, iwind said");
Copy after login

will output "i love kiki, kiki said"

Grammar:

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

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.

String deletion

$string = 'fdjborsnabcdtghrjosthabcrgrjtabc'; $string = preg_replace('/[abc]+/i','',$string);
Copy after login

Related recommendations:php training

The above is the detailed content of How to perform string replacement 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!