[ create a new paste ] login | about

Link: http://codepad.org/Qu7uPt0E    [ raw code | output | fork ]

PHP, pasted on Oct 6:
1
2
3
4
5
6
7
8
9
10
11
12
<?php

// our culprit
$str = json_encode(array("key" => "a\nb"));

echo $str; // contains \n

echo "\n";

echo str_replace("\\", "\\\\", $str); // \n escaped, safe

?>


Output:
1
2
{"key":"a\nb"}
{"key":"a\\nb"}


Create a new paste based on this one


Comments: