Php function str_replace usage summary _ PHP Tutorial

Source: Internet
Author: User
Summary of the use of the php function str_replace. String replacement. Syntax: stringstr_replace (stringneedle, stringstr, stringhaystack); return value: string function type: data processing content description this function replaces string str with string.
Syntax: string str_replace (string needle, string str, string haystack );
Return value: string
Function type: data processing
Description

This function substitutes str into the haystack string and replaces all needle with str. Mlevine@adtraq.com (11-Apr-1999) pointed out that in PHP 3.0.7, this function has some bugs, and the nadeem@bleh.org (05-Jun-1999) supplement in PHP 3.0.8 version function will return to normal.
Example

Replace % body % with black in the following example

<Php
$ Bodytag = str_replace ("% body %", "black ","");
Echo $ bodytag;
>

Format:
[@ Str_replace ("old content to be replaced", "new character to replace the original content", $ variable name of the content to be replaced)]
[@ Str_replace (array ('Old 1', 'old 2', 'old 3'), array ('New 1', 'New 2', 'New 3 '), $ variable name of the content to be replaced)]
[@ Str_replace (array ('Old 1', 'old 2', 'old 3'), 'New content', $ variable name of the content to be replaced)]
Instance:
Replace multiple-to-one: to replace all

Clear the tag and replace it with null.

[@ Str_replace (array ('

','

'), '', $ Content)]
One-to-one replacement: to replace all
Replace tags



[@ Str_replace ('
','

', $ Content)]
Many-to-many replacement: to replace
Change
, At the same time

In other words

Clear all

Bytes. Syntax: string str_replace (string needle, string str, string haystack); return value: string function type: data processing content description this function substitutes string str...

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.