Do I use fopen or curl to load an XML file given a URL in PHP?

Well, if you are going to use SimpleXML to load the file you can use simplexml_load_file($filename) However, some servers will restrict loading urls from this function. In this case you would be restricted to cURL.

Well, if you are going to use SimpleXML to load the file you can use simplexml_load_file($filename); However, some servers will restrict loading urls from this function. In this case you would be restricted to cURL.

This seems like the simplest solution for me to try first. Thanks! – dkinzer Apr 29 '10 at 19:04.

Allow_url_fopen, which is required if you want to open a remote file with fopen, can be disabled ; so, there are situations in which fopen('...') is not possible. Note : in this answer, I say "fopen", but it's exactly the same with all PHP functions that can access remote files : fopen, file_get_contents, simplexml_load_file, ... On the other hand, curl is an extension, and is not always enabled either. One nice with curl is that it's pretty easy to configure, and there are a lot of existing options (see curl_setopt) To configure the way fopen accesses remote files, it's a bit trickier -- you'll generally have to work with streams (see here, for example) ; and, generally speaking, there are more people knowing curl than there are developpers mastering streams.

Safest way -- especially if your application will be deployed to servers on which you are not administrator, and cannot re-configure : Try one solution And, if it doesn't work, try the other one.

Fopen is simpler to use, and I think not all server setups support curl out of the box. If fopen works fine for you it's probably your best choice.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions