Hello all, Ok so im am experimenting with xml and php never done this before, however I wish to turn each xml value into an array I can reference and later add to a db. (just for complexity xD)
I have modified some code I found on the net so far to this:
However, how would I go about changing $data to an array. So I could then reference a certain type of value. a value such as <playername> in the array such as ['playername']?
I have modified some code I found on the net so far to this:
PHP:
<?php
$file = "test.xml";
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");
$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);
?>
However, how would I go about changing $data to an array. So I could then reference a certain type of value. a value such as <playername> in the array such as ['playername']?