How to use PHP function str_replace Summary _php tutorial

Source: Internet
Author: User
String substitution.
Syntax: string str_replace (String needle, String str, String haystack);
return value: String
Function type: Data processing
Content Description

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

The following example replaces%body% with black

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

Format:
[@str_replace ("Old content to replace", "new character to replace original content", variable name of the replaced content)]
[@str_replace (' Old 1 ', ' Old 2 ', ' Old 3 '), Array (' New 1 ', ' New 2 ', ' new 3 '), $ replaced by the variable name of the content)]
[@str_replace (Array (' Old 1 ', ' Old 2 ', ' Old 3 '), ' new content ', ' variable name of the replaced content ')]
Instance:
Many-to-one substitution: Want to put all the content in the field

Label removed, replaced with empty

[@str_replace (The Array ('

','

'), ', $Content)]
One-to-one replacement: Want to put all the content in the field
Label Replace



[@str_replace ('
', '

', $Content)]
Many-to-many substitutions: you want to put the content field
Into
, while

Change, put

Clear All

http://www.bkjia.com/PHPjc/364526.html www.bkjia.com true http://www.bkjia.com/PHPjc/364526.html techarticle string substitution. Syntax: string str_replace (String needle, String str, String haystack); Return value: String function type: Data processing content Description This function will string str into ...

  • 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.