Skip to content

Instantly share code, notes, and snippets.

@rlemon
Created January 2, 2014 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlemon/50c867c07bc2088d661f to your computer and use it in GitHub Desktop.
Save rlemon/50c867c07bc2088d661f to your computer and use it in GitHub Desktop.
<?php
$goodhttpcodes = array(200,202,301,302,304);
$data = json_decode(file_get_contents('compress.zlib://http://api.stackoverflow.com/1.1/answers?body=true'));
foreach($data->answers as $answer) {
if(preg_match_all("|<a.*(?=href=\"([^\"]*)\")[^>]*>([^<]*)</a>|i", $answer->body, $matches)) {
foreach( $matches as $link ) {
$handle = curl_init($link[0]);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($handle);
$httpcode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
if(!in_array($httpcode, $goodhttpcodes) {
echo "dead link on ". $answer->answer_id .": " . $link[0] . "<br>";
}
curl_close($handle);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment