gerkintrigg Posted December 28, 2009 Share Posted December 28, 2009 I thought I'd post this in case someone finds it useful. It is a basic script I wrote to check whether links are valid within a grabbed piece of HTML code. I'm fairly convinced that this is not the best way to do it, but it works and is fairly quick, so if you want to use it, go ahead. <span class="title">Website links Check:</span><br /> <?php // a simple string $string = $_SESSION['page']; // put the matches in a variable called matches $url=preg_match_all('~<a href="(.*?)"(.*?)>~', $string, $matches); // loop through the array of matches and print them foreach($matches as $key=>$value){ if($key==1){ foreach($value as $second_key=>$second_value){ if(!$fp = @fopen($second_value, 'r')){ echo '<a href="'.$second_value.'" target="_blank">'.$second_value.'</a> - INVALID<br>'; } else{ echo '<a href="'.$second_value.'" target="_blank">'.$second_value.'</a> - OK<br>'; } } } } ?> A back link would be nice too. Link to comment https://forums.phpfreaks.com/topic/186467-website-link-checker-script/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.