I have a xml page
<response>
-
<item group="DATA" icon="http://*******************************/51337125.png">
<id>19209069</id>
<owner>8351976</owner>
<posts>156562</posts>
<subscribers>5128</subscribers>
-
<description>
kasjdlsajdlasjdlsadasdasdfjasdjashdk
</description>
</item>
</response>
Now I need to get each of the above tags in a variable. like $id = 19209069 and so on.. I do have a code to parse the XML(Listed below) but it only make the data in <b> tag. What i really need is to get it in a variable or in a array.. Pls help
<?php
$dat = array();
$file = "http://api.*******************************************"; //XML file
function contents($parser, $data){
echo $data;
}
function startTag($parser, $data){
echo "<b>";
}
function endTag($parser, $data){
echo "</b><br />";
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startTag", "endTag");
xml_set_character_data_handler($xml_parser, "contents");
// Opens the file for reading
$fp = fopen($file, "r");
$data = fread($fp, 80000);
if(!(xml_parse($xml_parser, $data, feof($fp)))){
die("Error on line " . xml_get_current_line_number($xml_parser));
}
xml_parser_free($xml_parser);
fclose($fp);
?>
<response>
-
<item group="DATA" icon="http://*******************************/51337125.png">
<id>19209069</id>
<owner>8351976</owner>
<posts>156562</posts>
<subscribers>5128</subscribers>
-
<description>
kasjdlsajdlasjdlsadasdasdfjasdjashdk
</description>
</item>
</response>
Now I need to get each of the above tags in a variable. like $id = 19209069 and so on.. I do have a code to parse the XML(Listed below) but it only make the data in <b> tag. What i really need is to get it in a variable or in a array.. Pls help
<?php
$dat = array();
$file = "http://api.*******************************************"; //XML file
function contents($parser, $data){
echo $data;
}
function startTag($parser, $data){
echo "<b>";
}
function endTag($parser, $data){
echo "</b><br />";
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startTag", "endTag");
xml_set_character_data_handler($xml_parser, "contents");
// Opens the file for reading
$fp = fopen($file, "r");
$data = fread($fp, 80000);
if(!(xml_parse($xml_parser, $data, feof($fp)))){
die("Error on line " . xml_get_current_line_number($xml_parser));
}
xml_parser_free($xml_parser);
fclose($fp);
?>