Forum Moderators: coopster
I want to use bits of data from external XML files and save them into a PHP array.
Currently I'm doing this as so...
$xml = simplexml_load_string(file_get_contents($xml_file_url));
But I'm getting some serious load time issues. The files are just too big. I only need a few bits of data from each file, not the whole thing. Hopefully this will speed up the page load time.
Is there a way of specifying which tags/nodes you want to use?
Thanks
To save file locally
$file = "http://example.com/feedurl";
$ch = curl_init($file);
$fp = @fopen("formvalues.xml", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
Then inside my form page I use
$filename = "formvalues.xml";
if (file_exists($filename)) {
$xml = simplexml_load_file($filename);
$titles = $xml->xpath("//select[@name='title']//option[@value]");
foreach($titles as $key => $value)
{
$titleddl[(string)$value['value']] = (string)$value;
}
...
}
WOW. I just did a quick search across the forums wondering if it was helping somebody else out here and got a hit. Details:
[webmasterworld.com...]
Using XMLReader [php.net] might be more appropriate for you, it reads one node at a time from the file without loading the whole thing into memory.
Andrew