Str_replace Function Summary _php base in PHP

Source: Internet
Author: User

Strings replaced.
Syntax: string str_replace (String needle, String str, String haystack);
return value: String
Function type: Data processing
Content Description

This function replaces the string str into the haystack string and replaces all needle with Str. Mlevine@adtraq.com (11-apr-1999) points out that in the PHP 3.0.7 version, this function has some bugs, and nadeem@bleh.org (05-jun-1999) complements the PHP 3.0.8 version function and returns to normal.
Usage examples

The following example replaces%body% with black

< PHP
$bodytag = Str_replace ("%body%", "Black", "<body text=%body%>");
Echo $bodytag;
>

Format:
[@str_replace ("Old content to replace", "new character to replace original content", $ substituted variable name)]
[@str_replace (Array (' Old 1 ', ' Old 2 ', ' Old 3 '), Array (' New 1 ', ' New 2 ', ' new 3 '), $ substituted variable name)]
[@str_replace (Array (' Old 1 ', ' Old 2 ', ' Old 3 '), ' new content ', $ substituted variable name)]
Instance:
Multi-pair substitution: To remove all <p></p> tags from the content field and replace them with empty

[@str_replace (' <p> ', ' </p> '), ', $Content]
One-to-one replacement: Want to replace all <br> tags in the content field with <p>

[@str_replace (' <br> ', ' <p> ', $Content)]
Multi-pair replacement: Want to change the Content field <br> to <br/&gt, while <p> for

Summary of str_replace function usage in PHP

PHP regular function Preg_replace () parameter description

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.