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 ("/[......