PHP Replacement String-str_replace

Source: Internet
Author: User
Instance

Replace the character "world" in the string "Hello world!" with "Shanghai":

<?phpecho Str_replace ("World", "Shanghai", "Hello world!");? >
Definition and usage

The Str_replace () function replaces some characters in a string with other characters (case-sensitive).

The function must adhere to the following rules:

  • If the searched string is an array, it returns the array.
  • If the searched string is an array, it will find and replace each element in the group.
  • If you need to find and replace an array at the same time, and you need to execute the replacement element less than the number of elements found, the extra element is replaced with an empty string
  • If you are looking for an array, instead of a string, the substitution string will work for all found values.

Note: The function is case-sensitive. Use the Str_ireplace () function to perform a case-insensitive search.

Note: This function is binary safe.

PHP Replacement String-str_replace

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.