How PHP implements the substitution of strings

Source: Internet
Author: User
Tags first string
This article to share the content of PHP is how to implement string substitution, has a certain reference value, the need for friends can refer to

Substr_replace (String,replacement,start,length)

The first argument is: the string to replace ( required )

The second argument is: Specify the string to replace ( required )

The third parameter is: Where to start the replacement ( required )

Positive number-begins the substitution at the specified position in the string
Negative number-replaces at the specified position from the end of the string

0-Start the substitution at the first character in the string

Fourth parameter: Specifies how many characters to replace ( optional )

Positive number-The length of the string being replaced
Negative-Indicates the number of characters at the end of the substring to be replaced.

0-Insert rather than replace


Cases:

$str = ' 220282198801011234 '; $new _str = Substr_replace ($str, ' ******** ', 6,8);p Rint_r ($new _str);

Print as follows:

220282******1234

Related recommendations:

An explanation of several string substitution functions in PHP

The first string in the PHP replacement string [Do not replace]

PHP: Commonly used string-related functions

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.