Jump to content

api; echo result-> browser interpretes html tags problem


Jeisson

Recommended Posts

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?

Edited by Jeisson
Link to comment
Share on other sites

the json is "body" : "<p></p>";

but I get echoed:

"body" : "

 

";

 

I think htmlspecialchars would change < to &lt, 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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.