How does rn match in PHP regular expressions?

Source: Internet
Author: User
How does rn match in PHP regular expressions? For example, a small string, \ r \ n
How to match \ r \ n?
(\ R \ n) + does not seem to work?


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 made a separate string and tried it. it is true, but the problem I encountered is:
I extracted a string from the database. this string contains a line break like \ r \ n, which is output directly to the browser as is. I want to use preg_replace
The two characters cannot be extracted in any way, such as "/(\ r \ n) +/" or replaced as you said, cannot match. The character string has been escaped when it is entered into the database. I'm sure the moderator can answer this question. why? Thank you very much.

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


I made a separate string and tried it. it is true, but the problem I encountered is:
I extracted a string from the database. this string contains a line break like \ r \ n, which is output directly to the browser as is. I want to use preg_replace
The two characters cannot be extracted in any way, such as "/(\ r \ n) +/" or replaced as you said, cannot match. The character string has been escaped when it is entered into the database. I'm sure the moderator can answer this question. why? Thank you very much.

Echo base64_encode (the content that you directly extract from the database );
Post result

Transfer

Php provides the nl2br function to do this.

Echo base64_encode (the content that you directly extract from the database );
Post result

Transfer

Php provides the nl2br function to do this.



The nl2br has been tried. it does not work because it is escaped as \ r \ n.
I use str_replace ("\ r \ n ","
", $ String); can be successfully replaced to meet the requirements.
Base64_encode:
W3NpemU9MjBdMjBweOeahOWtl + authorization + WIkue6v1svdV1cclxuW3Nd5Lit5YiS57q/authorization

$s = 'W3NpemU9MjBdMjBweOeahOWtl+S9k1svc2l6ZV1cclxuW2Jd5paH5a2X5Yqg57KXWy9iXVxyXG5baV3lgL7mlpxbL2ldXHJcblt1XeS4i+WIkue6v1svdV1cclxuW3Nd5Lit5YiS57q/Wy9zXVxyXG5bY29sb3I9I2YwMF3nuqLoibJbL2NvbG9yXVxyXG5bdXJsXWh0dHA6Ly93d3cuMTYzLmNvbVsvdXJsXVxyXG5bZW1haWxdcmVkXzAyNkAxNjMuY29tWy9lbWFpbF1cclxuW2ltZ11xcGljLzMvMzAuZ2lmWy9pbWdd';$s = base64_decode($s);echo nl2br(stripcslashes($s));
20 px font
Bold text
Skew
Underline
Dashes
[Color = # f00] Red [/color]
Http://www.163.com <br/> red_026@163.com

$s = 'W3NpemU9MjBdMjBweOeahOWtl+S9k1svc2l6ZV1cclxuW2Jd5paH5a2X5Yqg57KXWy9iXVxyXG5baV3lgL7mlpxbL2ldXHJcblt1XeS4i+WIkue6v1svdV1cclxuW3Nd5Lit5YiS57q/Wy9zXVxyXG5bY29sb3I9I2YwMF3nuqLoibJbL2NvbG9yXVxyXG5bdXJsXWh0dHA6Ly93d3cuMTYzLmNvbVsvdXJsXVxyXG5bZW1haWxdcmVkXzAyNkAxNjMuY29tWy9lbWFpbF1cclxuW2ltZ11xcGljLzMvMzAuZ2lmWy9pbWdd';$s = base64_decode($s);echo nl2br(stripcslashes($s));
20 px font
Bold text
Skew
Underline
Dashes
[Color = # f00] Red [/color]
Http://www.163.com <br/> 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.