Working with fopen and URL fetching…
I was coding a PHP rss reader for my site, one of the problems I had was when I found a none existant rss feed from the site that I was parsing. Instead of switching immediately to the ‘die’ part of the code, it would always stop in it’s tracks and print out that it couldn’t find the remote file.
Trying to create an error handling catch didn’t work the way I wanted it to with the code I got from google:
if (!($fp = fopen($file, “r”))) {
die(”could not open XML input”);
}
Searching a little further, I found a work around for PHP not to call these not found errors explicitly. That’s by preceding the function with a ‘@’.
if (!($fp = @fopen($file, “r”))) {
die(”could not open XML input”);
}
by modifying the code this way, PHP skips right away to the die portion.
Cool eh?
[source]