Wait, why not execute such a simple str_replace?

Source: Internet
Author: User
Wait, why not execute such a simple str_replace? $ S = 'AA \ r \ nbbb ';
$ S = str_replace ("\ r \ n", "", $ s );
Echo "s = $ s ";
Die ();

If chrome is used for debugging, \ r \ n cannot be replaced and wamp5.3 is used. I cannot find the error. could you please give me some advice?


Reply to discussion (solution)

$ S = 'AA \ r \ nbbb ';
I found the problem of single quotes.
$ S = "aa \ r \ nbbb ";
But what if I have to use single quotes?

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

\ R \ n is a common character in single quotes and a line break in double quotes.
It must be escaped in single quotes.

If single quotes are required, $ s = str_replace ('\ r \ n', "", $ s) below );

Variables in single quotes are not parsed as strings, and \ r \ n has special meanings in php, so they can also be considered as variables. Therefore, single quotes and double quotation marks are different in their resolution.

You can use single quotation marks or double quotation marks.

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.