Differences and explanations between PHPstr_replace () and str_ireplace ()

Source: Internet
Author: User
The difference between PHPstr_replace () and str_ireplace () is that the str_replace () function and str_ireplace () function in PHP are many functions in the program, its main function is to use a string to replace other characters in the string. The following describes the differences and explanations between Str_replace PHP str_replace () and str_ireplace ().

The str_replace () function and str_ireplace function of PHP are many functions in the program. Their main function is to use one string to replace other characters in the string. The following describes how to use it.

The Str_replace function is case sensitive. Use str_ireplace () to perform a case-insensitive search, and the rest should be no different.

Syntax
str_replace(find,replace,string,count)
Parameter description
Find Required. Specifies the value to be searched.
Replace Required. Required replacementFindValue.
String Required. Specifies the string to be searched.
Count Optional. A variable that counts the number of replicas.
Example 1
 str_replace("world","John","Hello world!")DE>;?>

Output:

Hello John!
Example 2

In this example, we will demonstrate the str_replace () function with array and count variables:

 str_replace("red","pink",$arr,$i)DE>);echo "Replacements: $i";?>

Output:

Array([0] => blue[1] => pink[2] => green[3] => yellow)Replacements: 1
Example 3
 str_replace($find,$replace,$arr)DE>);?>

Output:

Array([0] => B[1] =>[2] => !)

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.