How can I remove the linefeed rn from the php regular expression?

Source: Internet
Author: User
Php regular expression how to remove the line break rn now has such a string: abcxyzqwerty [abc] parse [abc] poiuytlkjhgf [abc] ddddddddeeeeeeeffff [abc] poiuyasdfg I want to use a regular expression, replace the linefeed (rn) between [abc] and [abc. But how can I remove the line break \ r \ n from the regular expression in AB php?
Now there is such a string:
Abcxyz
Qwerty
[Abc] aaaaaaaa
Bbbbbbbbb
Ccccccccc [/abc]
Poiuyt
Lkjhgf
[Abc]
Dddddd
Eeeeeee
Ffff [/abc]
Poiuy
Asdfg

I want to use a regular expression to replace the linefeed (\ r \ n) between [abc] and [/abc. However, linefeeds of strings other than [abc] and [/abc] remain unchanged.
The above is an example. it is possible that [abc] xxxx [/abc] [abc] ......, that is, the first [/abc] and the last [abc] are close to each other.

If it is compatible with linux and windows (line breaks seem to be different), it will be more perfect.

After one night, I consulted a group of friends and still did not solve the problem. I had to bother you.

------ Solution --------------------
If no nesting exists:
Preg_replace_callback ('~ \ [Abc \] (. *?) \ [/Abc \] ~ Msi ',
Function ($ matches ){
Return str_replace (array ("\ r", "\ n"), '', $ matches [0]);
},
$ Text );
------ Solution --------------------
PHP code
$ S = <TXTabcxyzqwerty [abc] hour [/abc] poiuytlkjhgf [abc] ddddddddeeeeeeeffff [/abc] poiuyasdfgTXT; echo preg_replace ('# \ [abc]. +? \ [/Abc] # se', 'preg _ replace ("/[\ r \ n] +/", "", "$0") ', $ s );
------ Solution --------------------
Discussion

PHP code
$ S = <TXT
Abcxyz
Qwerty
[Abc] aaaaaaaa
Bbbbbbbbb
Ccccccccc [/abc]
Poiuyt
Lkjhgf
[Abc]
Dddddd
Eeeeeee
Ffff [/abc]
Poiuy
Asdfg
TXT;

Echo preg_replace ('# \ [abc]. +? \ [/Abc] # se', 'preg _ replace ("/[......

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.