Question

I have a JSON Response like this:

 {
  "id":"2461",
  "name":"GEORGIA INSTITUTE OF <leo_highlight style=border-bottom: 2px solid rgb(255, 255, 150); background-c",
  "logo":"",
  "address":null,
  "city":null,
  "state":null,
  "campus_uri":"{{PATH}}2461\/"
 },
 ....
 ....

When I do strip_tgs on this one, the whole JSON string is getting truncated at the name tag above. The JSON string looks like this.

{"id":"2461","name":"GEORGIA INSTITUTE OF 

All below this line is gone. This is a huge JSON. But its getting truncated here. Any ideas on what to do? I need to strip out all HTML tags.

Update: Adding more details...

This JSON string I got is from encoding the query results array. So I get array from MySQL query and I encoded it with json_encode and trying to strip_tags on it.

Was it helpful?

Solution

$array = json_decode($json, true);
array_walk_recursive($array, function (&$val) { $val = strip_tags($val); });
$json = json_encode($json);

As simple... Decode it, walk through and encode it.

OTHER TIPS

Strip out the tags after you have decoded the JSON object. You might do this in a lazy fashion (i.e. when needed) rather than go through every item an strip tags on all fields.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top