hjortur17
1 month ago
233
22
General

Remove HTML from JSON object

Posted 1 month ago by hjortur17

I can't figure out how to remove HTML tags from JSON object. I'm getting data from a api but in the api there is some html tags. I have tried to json_decode and stuff but that did not work.

So what is the best way to remove html tags in PHP?

Here is example of the response from the api:

    12 => {#251 ▼
      +"date": "07:40"
      +"flightNumber": "<span class="cutoff" title="Brussels">Brussels</span>"
      +"airline": "FI554"
      +"to": "<span class="cutoff" title="Icelandair">Icelandair</span>"
      +"plannedArrival": "<span class="cutoff" title="Departed 07:50">Departed 07:50</span>"
      +"realArrival": "\r\n"
      +"status": null
    }
    13 => {#252 ▼
      +"date": "07:40"
      +"flightNumber": "<span class="cutoff" title="Berlin Tegel">Berlin Tegel</span>"
      +"airline": "FI528"
      +"to": "<span class="cutoff" title="Icelandair">Icelandair</span>"
      +"plannedArrival": "<span class="cutoff" title="Departed 07:52">Departed 07:52</span>"
      +"realArrival": "\r\n"
      +"status": null
    }

and here is how I'm getting this:

$content = json_decode(file_get_contents("https://apis.is/flight?language=en&type=departures"));

dd($content);

Please sign in or create an account to participate in this conversation.