How PHP regular expressions remove line breaks \ r \ n
Now there is this 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 line break between [ABC] and [/ABC] (that is, \ r \ n). However, the line breaks for strings other than [ABC] and [/ABC] remain unchanged.
The above is an example of this situation [ABC]XXXX[/ABC][ABC] ..., that is, the previous [/ABC] and the latter [ABC] are next to each other.
If you can be compatible with Linux and Windows (line breaks seem different), it's more perfect.
Get a night, ask a group of friends, still no solution, had to trouble everyone.
------Solution--------------------
If not nested:
Preg_replace_callback (' ~\[abc\] (. *?) \[/abc\]~msi ',
function ($matches) {
return Str_replace (Array ("\ r", "\ n"), ", $matches [0]);
},
$text);
------Solution--------------------
PHP code
$s =<<< Txtabcxyzqwerty[abc] Aaaaaaaabbbbbbbbbccccccccc[/abc]poiuytlkjhgf[abc]ddddddeeeeeeeffff[/abc]poiuyasdfgtxt;echo preg_replace (' #\[abc ].+?\[/ABC] #se ', ' Preg_replace ("/[\r\n]+/", "", "$ A") ', $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 ("/[...