I\'m having a strange problem when retrieving JSON formatted text. I use jQuery post
to send some data (also JSON formatted) to the server (running PHP) which w
Like Terw but with replacing \n
<?php
$json = str_replace('\n', '', $json);
?>
Should remove all line breaks, jquery shouldn't fail over
tags, but line breaks should not be in JSON.
do you get linebreaks like <br /> or newlines like \n? But try to replace them with PHP.
<?php
$string = 'asdfasf<br />asdfasf';
echo str_replace('<br />', '', $strin); // Replace <br /> with '' (nothing)
?>
or check out urlencode
Easy, just try:
<?php
...
function parseline($string){
$string = str_replace(chr(10), "//n", $string);
$string = str_replace(chr(13), "//n", $string);
return $string;
}
echo parseline($string_with_line_breaks);//returns json readable text
I have tested it and it works perfect. No need to add complicated functions.