I am trying to replace all the \n in a json string with a double pipe ||. Here is an example of a string :
{"comment":"test1
test2
test3"}';
Here is the regex I have done :
preg_match('/"comment":"(([^\n\t\r"]*)([\n\t\r]*))+"/', $a, $t);
The result of this preg_match is
Array
(
[0] => "comment":"test1
test2
test3"
[1] =>
[2] =>
[3] =>
)
I can't find what is wrong with my regexp.
Do I need a recursive pattern (?R) ?
Thanks.
\nchars then why you usepreg_match?commentvalue, and encode the data again. It's the easiest and safest way to go