I am trying to use echo to access the elements in an array but nothing happens.. When I use Print_r i get SimpleXMLElement Object() for each item that is supposed to be in the list.
This is what I have done
1. Load XML file with SimpleXML
2. created a function that puts the XML items into an array
3. created a function to errase the contents of the XML FILE
4. created a function to put the items in the array back into the xml file
step 1 and 2 are correct and allow me to use echo to retrieve the items in the array and display them
but when i perform step 3 and erase the xml file the echo no longer works....but the print_r will work by giving me SimpleXMLElement Object() in the display for every item instead of the actual item ccontent. what am i doing wrong?? Sorry if it is easy i am still very new to PHP . I will post the code ...it is important to get it working because i plan to make modify the array with php before reconstructing the xml file
Code: Select all
<?php
$xml = simplexml_load_file('photoFile.xml'); //loads the xml file
$blackhole = array(); //Array where all XML elements will be stored
//STEP 1//////////////////////////////////////
function xmlToArray($xml, &$blackhole)
{
$saveMe = $xml;
$i = 0;
foreach($saveMe->item as $item)
{
$blackhole[$i] = $item->location; //add string to current array index
$i++; //add 1 to the array number
}
}
// STEP 2 ////////////////////////////////////////
function erraseXML($xml)
{
foreach($xml->item as $item)
{
unset($xml->item); //Erases all top elements named item
}
echo "ERASING IS DONE";
}
///////////////DISPLAY ELEMENTS IN THE ARRAY NOT WORKING WITH ECHO
$counta = count($blackhole);
for($i=0; $i<$counta; $i++)
{
echo $blackhole[$i];
echo "<br />";
}
$xml->asXML('photoFile.xml'); //save the xml changes