Has your host got allow_url_fopen = Off and they’re too stubborn to turn it on? Got this error?
Warning: simplexml_load_file() [function.simplexml-load-file]: URL file-access is disabled in the server configuration in /url/to/file.php on line 62
It’s a pain for writing cool API clients that add cool functionality into your website, like using the Last.fm API, Amazon Associates Web Services, or the YouTube API, because they all use XML based services that you have to retrieve.
The simplest way is to use file_get_contents($url);, but that doesn’t work if allow_url_fopen = Off.
The next simplest way is to use libcurl, which although is very useful, has given me a lot of grief throughout my programming life, so is sort of my arch nemesis. I tried it on 1and1 trying to access AAWS, but it didn’t work anyway.
The last solution is my hacky little method to draw wget results into the script. This method is probably the slowest as we’re calling an external binary on a shared web server, but it works.
$url = "http://api.somesite.com/rest/xml?query=string&goes=here";
$user_agent = "My Awesome API Client v1.0";
ob_start();
passthru("wget -U '{$user_agent}' -q -O - '{$url}'");
$response = ob_get_contents();
ob_end_clean();
$xml_document = simplexml_load_string($response);
Last night I progressed a bit more with my new project, my own webmail client that will be used by myself, Tom and Hannah for our Total Carnage e-mails. It’s progressing quite well, and is very very AJAX orientated. So far, everything except loading the list of folders is done by AJAX (well, technically AJAJ as I prefer JSON to XML). So far, receiving mail works well, and you can now read and delete mails (although I’ve turned off permanent deletion for now). Take a look at the screenshot to the left to see what it currently looks like! I’m developing it with general users in mind, not just us three, so perhaps one day it might become my first publically released open-source project… Hah! Anyway, yes there is still much to do on it:
- Calendar (make compatible with .ics?)
- Contacts (make import from Hotmail/Gmail etc.?)
- Integration with GMail (download e-mails from Gmail)
- “Goal” scheduler
- Task list
- Full folder support
- Full spam&junk filter
- ?? Phishing filter ??
- Whatever takes my fancy really!
- Maybe make it WAP compatible?
I’ve always disliked XML really, I just feel it’s a bit bloated as a data container and parsing it in some languages can be unnecessarily complex. For AJAX-style requests I much prefer to use a format like JSON to transport data. Unfortunately, I need to keep up with the times and XML is already a major part of the internet, and is used in SOAP, RSS, Atom etc.. Therefore I like this class that a developer Anis uddin Ahmad has made. There’s probably loads of other classes like it, but this one is very simple to use, and by reading the author’s blog post, this is the intention. So I refer you now to the PHP Universal Feed Parser. I’m not sure how versatile it is, and what could break it yet, but it’s a cool idea and once I get a chance I’ll have a look at the source code and see how it works.
I found an interesting helper function today through the PHPDeveloper.org feed.
It’s as simple as the topic suggests – it’s a function that takes an XML formatted string and returns an array containing the results. Using the example from Michael’s msbware.com:
Example source XML:
<xmlData>
<author>
<name>John Doe</name>
<magazine>Time</magazine>
<magazine>National Geographic</magazine>
</author>
</xmlData>
Example result array with:
[xmlData][author][name] => John Doe
[xmlData][author][magazine][0] => Time
[xmlData][author][magazine][1] => National Geographic
The fact that the company I work for uses SourceSafe is really beginning to piss me off. I think I’m not the only one, but just take a look at this article:
http://www.highprogrammer.com/alan/windev/sourcesafe.html
Read the rest of this entry »