String function Library: Substr_replace

Source: Internet
Author: User
Keywords PHP Chinese function Manual Substr_replace
Tags aliyun echo function function library html http php php chinese function manual

Substr_replace

(PHP4 >= 4.0b4)

Substr_replace---&http://www.aliyun.com/zixun/aggregation/37954.html ">nbsp; A part of a string that replaces a string

Syntax: String substr_replace (String string, string replacement, int start [, int length])

Description:

Substr_replace () Replaces string partial strings, specifying the bounds by the parameter start and length, and substituting the parameter replacement.

If the argument start is a positive number, the substituted string begins with the first character of the string.

If the argument start is a positive number, the substituted string starts at the start character at the end of the string.

If there is a given parameter length and is a positive number, it represents the length of the part string to be replaced by the string. If length is negative, it represents the number of characters to be aborted from the end of a string. If this argument is not given, it is preset to the length of the parameter string.

Example:

<?php

$var = ' abcdefgh:/mnrpqr/';

echo "Original: $var <hr>\n";

/* This nonblank examples replace all $var with ' Bob '. */

Echo substr_replace ($var, ' Bob ', 0). "<br>\n";

Echo substr_replace ($var, ' Bob ', 0, strlen ($var)). "<br>\n";

/* Insert ' Bob ' right at the beginning of $var. */

Echo substr_replace ($var, ' Bob ', 0, 0). "<br>\n";

/* These next nonblank replace ' MNRPQR ' in $var with ' Bob '. */

Echo substr_replace ($var, ' Bob ', 10,-1). "<br>\n";

Echo substr_replace ($var, ' Bob ',-7,-1). "<br>\n";

/* Delete ' MNRPQR ' from $var. *

Echo substr_replace ($var, ', 10,-1). "<br>\n";

?>

Note: This function is the new function in PHP 4.0

Reference: Str_replace () substr ()

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.