How does RN match in a regular expression in PHP?

Source: Internet
Author: User
such as a string of small strings,\ r \ n
How to match to \ r \ n?
(\\r\\n) + not like it?


Reply to discussion (solution)

"/[\r\n]+/" must be placed in double quotation marks, otherwise \ r \ n will be interpreted as \, r, \, n
or '/[\x0d\x0a]+/'

I just made a string to try it out, yes, but the problem I encountered was:
I am a string from the database, this string contains \ r \ n Such a line break, the direct output to the browser is the output, I want to use Preg_replace
Replace these two characters, no matter what you can extract to these two characters, like "/(\\r\\n) +/" or as you say, replace, can not match to. The string entered the database has been escaped, it is sure that the moderator answer what is the reason? Thank you so much

"/[\r\n]+/" must be placed in double quotation marks, otherwise \ r \ n will be interpreted as \, r, \, n
or '/[\x0d\x0a]+/'


I just made a string to try it out, yes, but the problem I encountered was:
I am a string from the database, this string contains \ r \ n Such a line break, the direct output to the browser is the output, I want to use Preg_replace
Replace these two characters, no matter what you can extract to these two characters, like "/(\\r\\n) +/" or as you say, replace, can not match to. The string entered the database has been escaped, it is sure that the moderator answer what is the reason? Thank you so much

Echo Base64_encode (the content you are directly from the database);
Post the results

Turn

PHP provides a nl2br function, that's what this is about.

Echo Base64_encode (the content you are directly from the database);
Post the results

Turn

PHP provides a nl2br function, that's what this is about.



NL2BR tried, had no effect, because was escaped into the \\r\\n
I use Str_replace ("\\r\\n", "
", $string); is a requirement that can be successfully replaced.
Base64_encode Output Results:
w3npemu9mjbdmjbweoeahowtl+s9k1svc2l6zv1cclxuw2jd5pah5a2x5yqg57kxwy9ixvxyxg5bav3lgl7mlpxbl2ldxhjcblt1xes4i+ wikue6v1svdv1cclxuw3nd5lit5yis57q/ Wy9zxvxyxg5by29sb3i9i2ywmf3nuqloibjbl2nvbg9yxvxyxg5bdxjsxwh0dha6ly93d3cumtyzlmnvbvsvdxjsxvxyxg5bzw1hawxdcmvkxzaynkaxnjmuy 29twy9lbwfpbf1cclxuw2ltz11xcgljlzmvmzauz2lmwy9pbwdd

$s = ' w3npemu9mjbdmjbweoeahowtl+s9k1svc2l6zv1cclxuw2jd5pah5a2x5yqg57kxwy9ixvxyxg5bav3lgl7mlpxbl2ldxhjcblt1xes4i+ wikue6v1svdv1cclxuw3nd5lit5yis57q/ Wy9zxvxyxg5by29sb3i9i2ywmf3nuqloibjbl2nvbg9yxvxyxg5bdxjsxwh0dha6ly93d3cumtyzlmnvbvsvdxjsxvxyxg5bzw1hawxdcmvkxzaynkaxnjmuy 29twy9lbwfpbf1cclxuw2ltz11xcgljlzmvmzauz2lmwy9pbwdd '; $s = base64_decode ($s); Echo nl2br (Stripcslashes ($s));
Fonts in 20px
Text Bold
Tilt
Underline
Medium Dash
[Color= #f00] red [/color]
Http://www.163.com
Red_026@163.com

$s = ' w3npemu9mjbdmjbweoeahowtl+s9k1svc2l6zv1cclxuw2jd5pah5a2x5yqg57kxwy9ixvxyxg5bav3lgl7mlpxbl2ldxhjcblt1xes4i+ wikue6v1svdv1cclxuw3nd5lit5yis57q/ Wy9zxvxyxg5by29sb3i9i2ywmf3nuqloibjbl2nvbg9yxvxyxg5bdxjsxwh0dha6ly93d3cumtyzlmnvbvsvdxjsxvxyxg5bzw1hawxdcmvkxzaynkaxnjmuy 29twy9lbwfpbf1cclxuw2ltz11xcgljlzmvmzauz2lmwy9pbwdd '; $s = base64_decode ($s); Echo nl2br (Stripcslashes ($s));
Fonts in 20px
Text Bold
Tilt
Underline
Medium Dash
[Color= #f00] red [/color]
Http://www.163.com
Red_026@163.com



Thank you very much!
  • 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.