Created
March 21, 2011 20:10
-
-
Save rmarscher/880114 to your computer and use it in GitHub Desktop.
PHP function that automates detecting if an open graph page has errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Function to automate detecting if an open graph page has errors | |
* Requires the dom php extension to be enabled | |
* | |
* @param string $url | |
* @return array with keys 'hasError', 'errorType', and 'errorMessage' | |
*/ | |
function facebookLinterErrors($url) | |
{ | |
$errorType = ""; | |
$errorMessage = ""; | |
$hasError = false; | |
try { | |
$linterPage = DOMDocument::loadHTMLFile("http://developers.facebook.com/tools/lint/?url=" . urlencode($url) . "&_fb_noscript=1"); | |
$error = $linterPage->getElementById('lint_error'); | |
if ($error != null && $error->hasChildNodes()) { | |
$errorType = $error->lastChild->lastChild->firstChild->nodeValue; | |
$errorMessage = $error->lastChild->lastChild->lastChild->nodeValue; | |
$hasError = true; | |
} | |
} catch (Exception $e) {} | |
return compact('hasError', 'errorType', 'errorMessage'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment