Home > Article > Backend Development > Summary of how to use php function str_replace_PHP tutorial
String replacement.
Syntax: string str_replace(string needle, string str, string haystack);
Return value: String
Function type: Data processing
Content description
This function converts a string into Substitute str into the haystack string and replace all needles with str. mlevine@adtraq.com (11-Apr-1999) pointed out that in PHP version 3.0.7, this function has some bugs, while nadeem@bleh.org (05-Jun-1999) added that in PHP version 3.0.8, the function returns to normal. .
Usage Example
The following example replaces %body% with black
< php
$bodytag = str_replace("%body%", "black", "< body text=%body%>");
echo $bodytag;
>
Format:
[@str_replace("Old content to be replaced", "To replace the original New characters of the content", $Variable name of the replaced content)]
[@str_replace(array('old1','old2','old3'), array('new1','new2 ', 'New 3'), $Variable name of the replaced content)]
[@str_replace(array('Old 1', 'Old 2', 'Old 3'), 'New content', $ is replaced Variable name of content)]
Example:
Many-to-one replacement: I want to clear all
','
'), '', $Content)]', $Content)]
Many-to-many replacement: I want to replace the
in the content field into
, and replace
with