<?php
$xml_data = '<news_list max_id="101">
<news pref="" pos="11" id="100" data="27%2F03%2F2009" titolo="UltraMusic Festival" locale="Miami (USA)" />
<news pref="" pos="11" id="100" data="27%2F03%2F2009" titolo="Mansion" locale="Miami (USA)" />
<news pref="" pos="11" id="100" data="03%2F04%2F2009" titolo="El San Juan Hotel" locale="San Juan (PRI)" />
<news pref="" pos="11" id="100" data="04%2F04%2F2009" titolo="Teatro La Fiesta" locale="Santo Domingo (DOM)" />
<news pref="" pos="11" id="100" data="22%2F06%2F2009" titolo="SHM & Friends Mondays @ Pacha" locale="Ibiza (E)" />
<news pref="" pos="11" id="100" data="10%2F07%2F2009" titolo="Oxegen Festival" locale="Punchestown (IRL)" />
<news pref="" pos="11" id="100" data="12%2F08%2F2009" titolo="Green Beat Festival" locale="Pag Island (HR)" />
<news pref="" pos="11" id="100" data="29%2F08%2F2009" titolo="Creamfields" locale="Liverpool (UK)" />
<news pref="" pos="11" id="100" data="30%2F08%2F2009" titolo="Creamfields" locale="Liverpool (UK)" />
</news_list>';
class SimpleXMLElementExtended extends SimpleXMLElement{
public function getAttribute($name){
foreach($this->attributes() as $key=>$val){
if($key == $name){
return (string)$val;
}// end if
}// end foreach
}// end function getAttribute
public function getChildrenCount(){
$cnt = 0;
foreach($this->children() as $node){
$cnt++;
}// end foreach
return (int)$cnt;
}// end function getChildrenCount
}
$xml2 = new SimpleXMLElementExtended($xml_data);
print('<strong>NUMBER OF GIGS</strong>: '.$xml2->getChildrenCount());
print('<br /><br />');
$i = 0;
while ($i < $xml2->getChildrenCount()){
print('<strong>GIG TITLE</strong>: '.$xml2->news[$i]->getAttribute('titolo'));
print('<br />');
print('<strong>GIG DATE</strong>: '.$xml2->news[$i]->getAttribute('data'));
print('<br /><br />');
$i++;
}
?>
$xml_data = file_get_contents('http://your.mom.com/something.xml');
$url = 'http://your.mom.com/something.xml';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$xml = curl_exec($ch);
Registrerte brukere: Google [Bot]