-
☆ A M B ☆
- 24,524 Posts
I’m trying to figure out how to access a remote xml feed in a snippet without getting the ugly MODx php error message if the xml server is not available.
I’ve tried passing the URL to the file_exists() function, but that always returns false.
If your server supports curl, you might try that.. you can get the http response code from CURLINFO_HTTP_CODE. I believe it’s something like:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.someurl.com/file.xml");
curl_setopt($ch, CURLINFO_HTTP_CODE, $httpCode);
$data = curl_exec($ch);
curl_close($ch);
if ($httpCode == 404) { ... }
//or just
if ($data) { ... }
?>
"He can have a lollipop any time he wants to. That's what it means to be a programmer."