-
-
Save rlemon/50c867c07bc2088d661f to your computer and use it in GitHub Desktop.
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
<?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