Find my Json code.
$result = {
"text_1":
[
{
"text": "Name \nKarSho",
"left": 0,
"right": 0
}
]
}
I want "text" from this Json in PHP. I used following script,
$json = json_decode($result,true);
if($json && isset($json['text_1']))
{
$textblock =$json['text_1'][0];
echo $textblock['text'];
}
It's giving,
Name KarSho
But I want,
Name \nKarSho
What to do?
Well, to your surpeize, it will give you,
Name \nKarShoas output, But when you render that in HTML (In any Browser), You will not see a new line, because more than one spaces and new lines are ignored by browsers, if you go to view source of the browser, you will see a new line there,If you want your HTML to show the new line, use
So that your new lines will be converted to
<br>tag, and you will see that in your HTML output.Edit:
If you want to see also
\nin output (as is), You just wantand to remove the quotes,