Forum Moderators: coopster
Thanks,
$sql = "SELECT link FROM table";
$result = mysql_query($sql) or die();
while($row = mysql_fetch_assoc($result)){
unset($lines);
@$lines = file($row['link']);
if($lines){
$link = false;
foreach ($lines as $line_num => $line) {
if(strstr($line,"href='http://www.mysite.com'") ¦¦ strstr($line,"href=\"http://www.mysite.com\"")){
echo "<span style='color:green;font-weight:bold'>LINK EXISTS</span>";
$link = true;
break;
}
}
if(!$link){
echo "<span style='color:red;font-weight:bold'>NO LINK</span>";
}
echo " ==> ".$row['link']."<br>";
}
else{
echo "Could not open ".$row['link']."<br>";
}
}
$sql = "SELECT link FROM table";
$result = mysql_query($sql) or die();
$pattern = "/href=['\"]http:\/\/(www\.)?example\.com['\"]/i";
while($row = mysql_fetch_assoc($result)){
if($file = [url=http://us3.php.net/manual/en/function.file-get-contents.php]file_get_contents[/url]($row['link'])) {
echo '<span style="color:green;font-weight:bold">';
echo ([url=http://us3.php.net/manual/en/function.preg-match.php]preg_match[/url]($pattern,$file))?'LINK EXISTS':'NO LINK';
echo '</span>';
}
echo " ==> ".$row['link'].'<br/>';
}
You might have to check up on my pattern syntax. My brain isn't working well right now ;)
@$lines = file($row['link']);
To this:
$lines = file($row['link']); //notice I removed error suppression here
This will tell you exactly why you are not getting the file content. I would, however, try to implement a solution similar to mine as having a loop within a loop is messy :)
Sorry I didn't answer your question off the bat. Let me know what you get from this if you need any more help.
Good luck!
You should try to implement my solution and then debug from there.
Trying something simple in its own php file could tell you too:
$file = file("http://www.example.com"); //make it static just for testing
echo '<pre>';
print_r($file);
echo '</pre>';