I have searched and searched but it seems i'm the only one having this problem. So I want to convert line breaks from this $_GET variable. So this is my url:
test.php?name=Line%201\nLine%202\rLine%203\r\nLine%204
In my code I have tried:
print nl2br($_GET['name']); //doesn't work
I have also tried:
print str_replace(array("\r\n", "\r", "\n"), "<br>", $name); //doesn't work
Every time it prints out the original string (Line 1\nLine 2\rLine 3\r\nLine 4\n) with no change. However if I try it with a variable that is not passed in it always works. For instance:
$other = "Line 1\nLine 2\rLine 3\r\nLine 4\n";
print `nl2br($_GET['name']);
print str_replace(array("\r\n", "\r", "\n"), "<br>", $other);
I have also tried doing this in a tottaly new document, where I don't have any "sanitizing" scripts or any other scripts still can't get around it...
I suspect this is because the characters sent are literally '\n' not a newline.
The GET request should probably be something like First+line%0ASecond+line
;
If you can't change the request you can change the replace to escape the slashes:
print str_replace(array("\\r\\n", "\\r", "\\n"), "<br>", $name);