Urgency, such a simple str_replace, how not to execute it?

Source: Internet
Author: User
$s = ' aa\r\nbbb ';
$s =str_replace ("\ r \ n", "", $s);
echo "s= $s";
Die ();

This I use chrome, no matter how debugging, is to replace the \ r \ n, with the wamp5.3, I really can not find the wrong, please expert guidance?


Reply to discussion (solution)

$s = ' aa\r\nbbb ';
I found out it was a single quote question written
$s = "aa\r\nbbb"; it's fine.
But what if I have to use single quotes?

Replace with single quotes.
$s =str_replace (' \ r \ n ', ' ", $s);

\ r \ n is a normal character in single quotation marks and a newline in double quotation marks.
Must be escaped with single quotation marks.

If you must use single quotation marks, then the bottom $s=str_replace (' \ r \ n ', ' ", $s);

A variable in single quotes is not parsed as a string and \ r \ n is a special meaning in PHP, so it can also be treated as a variable. So the single and double quotes are different for their resolution.

You can use single quotes or double quotes both up and down.

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