Home > Backend Development > PHP Tutorial > Summary of how to use php function str_replace_PHP tutorial

Summary of how to use php function str_replace_PHP tutorial

WBOY
Release: 2016-07-21 14:54:56
Original
1050 people have browsed it

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

tags in the content field and replace them with empty

[@ str_replace(array('

','

'), '', $Content)]
One-to-one replacement: I want to replace all
tags in the content field with < ;p>

[@str_replace('
', '

', $Content)]
Many-to-many replacement: I want to replace the
in the content field into
, and replace

with


, clearing all

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364526.htmlTechArticleString replacement. Syntax: string str_replace(string needle, string str, string haystack); Return value: String Function type: Data processing Content description This function substitutes the string str into...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template