Jump to content

Website Link Checker Script


gerkintrigg

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.