Jump to content

SimpleXML help


devWhiz

Recommended Posts

Ok so I have a url that is an XML doc, it says at the top

 

"This XML file does not appear to have any style information associated with it. The document tree is shown below."

 

and it has info like this

 


<outer>
  <xml>
    <viewer>
      <user>
        <id>1245789</id>
        <name>CLueless</user>
        <business>none</business>
      </user>
    </viewer>
  </xml>
</outer>

 

How would I load the link and then assign everything to a variable like id, name and business

 

I usually use something like this but Im trying to get learn simple xml

 


$info = file_get_contents('url');
$id = explode('<id>', $info);
$id = explode('</', $id[1]);
$name = explode('<name>', $info);
$name = explode('</', $name[1]);
$biz = explode('<business>', $info);
$biz = explode('</', $biz);

Link to comment
https://forums.phpfreaks.com/topic/233783-simplexml-help/
Share on other sites

note you have a tag mismatch "<name>CLueless</user>"

<?php
  $xml_feed="<outer>
  <xml>
    <viewer>
      <user>
        <id>1245789</id>
        <name>CLueless</name>
        <business>none</business>
      </user>
    </viewer>
  </xml>
</outer>
";

if(!$xml = simplexml_load_string("$xml_feed")){
    echo "Can't connect to feed $xml_feed";
}else{
foreach ($xml->xml->viewer->user as $value){ 
$id=$value->id;
$name=$value->name;
$biz=$value->business;
echo"id=$id<br />\n";
echo"name=$name<br />\n";
echo"biz=$biz<br />\n";

}  
    
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/233783-simplexml-help/#findComment-1201933
Share on other sites


$xmll = file_get_contents('http://mob-dynamic-lb5.mobsters04.com/mob/refresh_stat_manual?user_id=496046235&session_id=');
$xml = simplexml_load_string($xmll);
foreach ($xml->xml->viewer->user as $value){ 
$id=$value->user_name;
$name=$value->user_id;
$biz=$value->error;
echo"id=$id<br />\n";
echo"name=$name<br />\n";
echo"biz=$biz<br />\n";
sleep(10000);
}  
    

what am I doing wrong

Link to comment
https://forums.phpfreaks.com/topic/233783-simplexml-help/#findComment-1202289
Share on other sites


$xmll = file_get_contents('http://mob-dynamic-lb5.mobsters04.com/mob/refresh_stat_manual?user_id=496046235&session_id=');
$xml = simplexml_load_string($xmll);
foreach ($xml->xml->viewer->user as $value){ 
$id=$value->id;
$name=$value->name;
$error=$value->error;
echo"id=$id<br />\n";
echo"name=$name<br />\n";
echo"error=$error<br />\n";
sleep(10000);
}  
    

what am I doing wrong

Link to comment
https://forums.phpfreaks.com/topic/233783-simplexml-help/#findComment-1202290
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.