Amanda_Panda
Amanda_Panda

Reputation: 1186

Getting rid of <br> tags in parsing XML

I'm parsing the XML from BART's website at http://www.bart.gov/dev/eta/bart_eta.xml I want to parse a single station, lets say Millbrae:

<?php
$xml = simplexml_load_file('http://bart.gov/dev/eta/bart_eta.xml');

foreach($xml->station as $station){
 if($station->name=="Millbrae"){
  foreach($station->eta as $eta) {
    echo $eta->destination;
    echo "<br>";
    echo $eta->estimate;
    echo "<br>";
    }}
  }
?>

That outputs the correct data from Millbrae, but the output has a lot of
tags-its as if it outputs the entire xml file until it gets to Millbrae, rather than just Millbrae. Is there a way to get rid of all those
tags? I am just learning php and html, so I am not even sure if I'm asking this question properly.

Thanks

Upvotes: 2

Views: 261

Answers (1)

ThinkingMonkey
ThinkingMonkey

Reputation: 12727

Look into PHP manual: strip_tags.

function strip_tags — Strip HTML and PHP tags from a string

You can do it like this:

<?php
$xml = simplexml_load_file('http://bart.gov/dev/eta/bart_eta.xml');

foreach($xml->station as $station) {
 if($station->name=="Millbrae") {
  foreach($station->eta as $eta) {

    echo strip_tags ($eta->destination); //use strip_tags here
    echo "<br>";
    echo strip_tags ($eta->estimate); //use strip_tags here
    echo "<br>";
    }
  }
 }

?>

Upvotes: 2

Related Questions