我正在尝试制作一个脚本,该脚本将加载所需的 URL(由用户输入)并检查该页面是否在其域发布到我的网站之前链接回我的域。我对正则表达式不是很有经验,这就是我到目前为止所拥有的:
$loaded = file_get_contents('http://localhost/small_script/page.php');
// $loaded will be equal to the users site they have submitted
$current_site = 'site2.com';
// $current_site is the domain of my site, this the the URL that must be found in target site
$matches = Array();
$find = preg_match_all('/<a(.*?)href=[\'"](.*?)[\'"](.*?)\b[^>]*>(.*?)<\/a>/i', $loaded, $matches);
$c = count($matches[0]);
$z = 0;
while($z<$c){
$full_link = $matches[0][$z];
$href = $matches[2][$z];
$z++;
$check = strpos($href,$current_site);
if($check === false) {
}else{
// The link cannot have the "no follow" tag, this is to check if it does and if so, return a specific error
$pos = strpos($full_link,'no follow');
if($pos === false) {
echo $href;
}
else {
//echo "rel=no follow FOUND";
}
}
}
如您所见,它非常混乱,我完全确定它的发展方向。我希望有人能给我一个小巧、快速、简洁的脚本,它可以完全按照我的尝试进行。
- 加载用户输入的指定 URL
- 检查指定的 URL 是否链接回我的网站(如果没有,返回错误代码 #1)
- 如果链接存在,请检查“不关注”,如果找到则返回错误代码 #2
- 如果一切正常,请将变量设置为 true,这样我就可以继续使用其他功能(例如在我的页面上显示它们的链接)