irreplacable PHP Substr_replace will specify that the characters between the two positions be replaced by the number

Source: Internet
Author: User
Copy CodeThe code is as follows:


$username = "Zongzi";
Echo substr_replace ($username, ' * * ', ' 1 ', ' 2 ');


Definition and usage

The Substr_replace () function replaces part of a string with another string.

Grammar

Substr_replace (String,replacement,start,length)
Parameters Description
String Necessary. Specifies the string to check.
Replacement Necessary. Specifies the string to insert.
Start

Necessary. Specifies where the string begins to be replaced.

  • Positive number-starts with the first offset
  • Negative number-replaces the start offset starting at the end of a string
  • 0-Start the substitution at the first character in the string
Charlist

Optional. Specifies the number of characters to replace.

  • Positive number-The length of the string being replaced
  • Negative-the number of characters to be replaced starting at the end of the string
  • 0-Insert rather than replace

Hints and Notes

Note: If start is negative and length is less than or equal to start, length is 0.
Example

Copy the Code code as follows:


Echo substr_replace ("Hello World", "Earth", 6);
?>


Output:
Hello Earth

The above describes the irreplacable PHP substr_replace will specify the characters between the two positions to replace the number, including the irreplacable aspect of the content, I hope to be interested in PHP tutorial friends helpful.

  • Related Article

    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.