Jeisson Posted September 28, 2015 Share Posted September 28, 2015 Hello i GET with api Json, The browser interpretes the html tags in the Json, so linting is not possible. i' assume the decoding is not affected? //here I define the base url first, then $url = $base_url;$results = file_get_contents($url);echo $results;exit;//Problem is that the browser interprete the html tags inside the Json. So I cannot lint the result. Q. How do i echo tags as text only in this case? Anyway if I $json_results = json_decode($results,true); Will that be in its order and clean? how can I Lint that result? Link to comment https://forums.phpfreaks.com/topic/298343-api-echo-result-browser-interpretes-html-tags-problem/ Share on other sites More sharing options...
iarp Posted September 28, 2015 Share Posted September 28, 2015 Do you have control of the sending side, whereever $url is pointing to? Can you give us the output you see from echo $results; Link to comment https://forums.phpfreaks.com/topic/298343-api-echo-result-browser-interpretes-html-tags-problem/#findComment-1521710 Share on other sites More sharing options...
scootstah Posted September 28, 2015 Share Posted September 28, 2015 You can either write to a file or use htmlspecialchars to display the raw HTML. Link to comment https://forums.phpfreaks.com/topic/298343-api-echo-result-browser-interpretes-html-tags-problem/#findComment-1521712 Share on other sites More sharing options...
Jeisson Posted September 28, 2015 Author Share Posted September 28, 2015 the json is "body" : "<p></p>"; but I get echoed: "body" : " "; I think htmlspecialchars would change < to <, right? Anyway the decode dont get confused of html tags, is it so? Link to comment https://forums.phpfreaks.com/topic/298343-api-echo-result-browser-interpretes-html-tags-problem/#findComment-1521721 Share on other sites More sharing options...
scootstah Posted September 28, 2015 Share Posted September 28, 2015 the json is "body" : "<p></p>"; but I get echoed: "body" : " "; I think htmlspecialchars would change < to <, right? Yes. Then you'd be able to see the HTML on your screen. The other way is to write the response to a file, and then you'd have the raw response body. $results = file_get_contents($url); file_put_contents('response.txt', $results); Anyway the decode dont get confused of html tags, is it so? json_decode() does not care about HTML. Link to comment https://forums.phpfreaks.com/topic/298343-api-echo-result-browser-interpretes-html-tags-problem/#findComment-1521725 Share on other sites More sharing options...
Jeisson Posted September 28, 2015 Author Share Posted September 28, 2015 my echo wass/is only for linting. And my question here for learning. so file.txt is too clumsy in my opion. but I got the thing done with htmlspecialchars, I knew it was easy but only when known how to be done. thanks! Link to comment https://forums.phpfreaks.com/topic/298343-api-echo-result-browser-interpretes-html-tags-problem/#findComment-1521744 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.