Summary of str_replace functions in php

Source: Internet
Author: User

String replacement.
Syntax: string str_replace (string needle, string str, string haystack );
Return Value: String
Function Type: Data Processing
Description

This function substitutes str into the haystack string and replaces all needle with str. Mlevine@adtraq.com (11-Apr-1999) pointed out that in PHP 3.0.7, this function has some bugs, and the nadeem@bleh.org (05-Jun-1999) supplement in PHP 3.0.8 version function will return to normal.
Example

Replace % body % with black in the following example

<Php
$ Bodytag = str_replace ("% body %", "black", "<body text = % body %> ");
Echo $ bodytag;
>

Format:
[@ Str_replace ("old content to be replaced", "new character to replace the original content", $ variable name of the content to be replaced)]
[@ Str_replace (array ('old 1', 'old 2', 'old 3'), array ('new 1', 'new 2', 'new 3 '), $ variable name of the content to be replaced)]
[@ Str_replace (array ('old 1', 'old 2', 'old 3'), 'new content', $ variable name of the content to be replaced)]
Instance:
Replace multiple-to-one: to clear all <p> </p> labels in the content field, replace them with null.

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

[@ Str_replace ('<br>', '<p>', $ Content)]
Replace multiple-to-multiple: replace <br> with <br/> In the content field, <p> change
Summary of str_replace function usage in PHP

Php Regular Expression 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.