0

Hi I want to parse in php

and read only one option of each line. How can I do this?

I tried:

<?php
$xml = file_get_contents("file.xml");
echo $xml;
?>

But this read the full xml. I need only one option of the xml

Can
  • 553
  • 1
  • 9
  • 29

2 Answers2

0

Try this

<? php $xml = simplexml_load_file("path/to/your/file/file.xml"); ?>

Convert your object into array like this

$array= (array) $xml;

after that you can do this

$option = $array['OptionName'];
Can
  • 553
  • 1
  • 9
  • 29
Red Bottle
  • 2,839
  • 4
  • 22
  • 59
0

Take a look at simplexml_load_file and turn your xml into a workable object where you can loop through and find whichever properties you need.

$xml = simplexml_load_file('file.xml');

foreach($xml->ParkingData as $k => $v)
echo $v->ParkingFacility->ParkingName ." - Vacant Spaces: ". $v->ParkingFacility->VacantSpaces."<br />";
Dano
  • 169
  • 9