I'm requesting information from a remote server which is sent back to me as XML, I use SimpleXML to parse it. However I need to load multiple URLs, can I do so through one file, or do I need to have a different file for each request?
My code looks something like this
$url = 'http://...';
$xml = simplexml_load_file($url);
Thanks!
You can create a loop that deals with the multiple urls...
$all_urls = array('http://url1', 'http://url2', 'http://url3'); foreach ($all_urls as $url) { $xml = simplexml_load_file($url); }
Create a function and place '$xml = simplexml_load_file($url)' into it. Then you can call the function from within a LOOP. That's the only way I am able to get it to call simplexml_load_file($url) more than once within a loop.
$all_urls = array('url1', 'url2', 'url3');
foreach ($all_urls as $url) {
importXml($url);
}
function importXml($url){
$xml = simplexml_load_file($url);
//Do stuff...
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.