Php string and character replacement functions

Source: Internet
Author: User
Tags chr php tutorial

Replacing characters in the php Tutorial is the most efficient and simplest character replacement function str_replace ($ arr1, $ arr2, $ str)
Instance 1

The code is as follows: Copy code
Str_replace ("iwind", "kiki", "I love iwind, iwind said ");
Output "I love kiki, kiki said"

Result

Replace all "iwind" in the original string with "kiki ". str_replace is case sensitive, so you cannot imagine using str_replace ("iwind", "kiki ",...) replace "iwind" in the original string ". str_replace can also implement multiple-to-one

Definition and usage
The str_replace () function uses one string to replace other characters in the string.

Syntax
Str_replace (find, replace, string, count) parameter description
Find is required. Specifies the value to be searched.
Replace is required. Specifies the value to replace the value in find.
String is required. Specifies the string to be searched.
Count is optional. A variable that counts the number of replicas.

 

Use one of the following

// -- Program name: strreplace ()
// -- Program purpose: replace invalid characters in the variable
// -- Input parameter: variable value
//************************************** ******************

The code is as follows: Copy code

Function strreplace ($ str ){
$ Str = strips tutorial lashes ($ str );
$ Str = str_replace (chr (92), '', $ str );
$ Str = str_replace (chr (47), '', $ str );
$ Str = str_replace (chr (10). chr (13), "<br>", $ str );
$ Str = str_replace ('<', "& lt;", $ str );

$ Str = str_replace ('>', "& gt;", $ str );
$ Str = str_replace (';', ";", $ str );
$ Str = str_replace ('"'," ", $ str );
$ Str = str_replace ("'", "'", $ str );
$ Str = str_replace ("", "", $ str );
$ Str = str_replace ("/**/", "", $ str );

Return trim ($ str );
}

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.