D
D
des1roer2017-02-07 15:01:20
PHP
des1roer, 2017-02-07 15:01:20

Parse xml in PHP?

I get curly

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<vars>
<city id="2">ввг</city><city id="11">вИсток п</city><city id="7">а пг</city><city id="5">рс</city><city id="1">ааааааг</city><city id="3">аааг</city><city id="12">ааааас</city><city id="14">ааас</city><city id="20">аап</city><city id="17">ааап</city><city id="10">4444с</city><city id="6">уууг</city><city id="8">аааап</city><city id="13">Светлый пос</city><city id="4">Станция ааааа</city><city id="9">аааааыг</city><city id="16">ап</city><city id="19">апгт</city></vars>

I see this in the page code,
but $response = simplexml_load_string($response); does not display the id that is in the city block, but simply creates a one-dimensional array
how to get all the data

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
des1roer, 2017-02-07
@des1roer

$xml = simplexml_load_string($response);

for($i=0, $cnt = count($xml); $i < $cnt; $i++){
  echo $xml->city[$i][0]; echo ' ';   
  echo $xml->city[$i]->attributes()->id;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question