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/>, while <p> for
Summary of str_replace function usage in PHP
PHP regular function Preg_replace () parameter description