Manipulate XML with PHP [closed]

7

Can anyone tell me how I can get just the name value in the code below.

index page.

<?php

$curl = curl_init('http://localhost/server.php');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$resultado = curl_exec($curl);
curl_close($curl);

$xml = simplexml_load_string ($resultado);

echo $resultado;
echo $xml->nome;
?>

Server page:

$note=<<<xml
<note>
<nome>xiro</nome>
</note>
xml;

$xml = simplexml_load_string ($note);
var_dump($xml);
    
asked by anonymous 05.03.2015 / 23:39

2 answers

0

You also have to pass the "Parent" parameters of the element.

$xml->note->nome;

Since you can see <nome> is within <note> then you will have to set note in the code.

    
06.03.2015 / 00:02
0

You have to make a foreach in XML, see it's very simple:

<?php
$note=<<<xml
<note>
<nome>xiro</nome>
</note>
xml;

$xml = simplexml_load_string($note);

echo $xml->getName() . "<br>";

foreach($xml->children() as $child) {
    echo $child->getName() . ": " . $child . "<br>";
}

Here's a demo

    
26.11.2015 / 13:55