检测连接

  • 内容
  • 评论
  • 相关
1 <?php 2 3 /** 4 * 检查在执行页面是否存在本站链接 5 * @param string $reurl 6 * @return boolean 7 */ 8 function check_url(array $arr){ 9 $siteUrl = "http://www.haojumei.com"; 10 $reurlArr = parse_url($arr['reurl']); 11 $urlArr = parse_url($arr['url']); 12 $found = false; 13 if($reurlArr['host'] == $urlArr['host']){ 14 $html = file_get_contents ( $arr['reurl'] ); 15 $html = strtolower ( $html ); 16 $site_url = strtolower ( $siteUrl ); 17 if (preg_match_all ( '/<a\s[^>]*href=([\"\']??)([^" >]*?)\\1([^>]*)>/siU', $html, $matches, PREG_SET_ORDER )) { 18 foreach ( $matches as $match ) { 19 if ($match [2] == $siteUrl || $match [2] == $siteUrl . '/') { 20 $found = true; 21 break; 22 } 23 } 24 } 25 } 26 return $found; 27 }