> php教程 > php手册 > 百度小偷:去除竞价与广告

百度小偷:去除竞价与广告

WBOY
풀어 주다: 2016-06-21 08:55:46
원래의
966명이 탐색했습니다.

功用如题。
重写规则和Wordpress一致。
兼容IIS、Apache、Nginx。
只有一个文件实现所有功能。
 

<ol class="dp-xml">
<li class="alt"><span><span class="tag"></span><span class="tag-name">php</span><span> </span></span></li>
<li><span>if(isset($_GET['wd'])){  </span></li>
<li class="alt">
<span>    $</span><span class="attribute">keywords</span><span> = $_GET['wd'];  </span>
</li>
<li><span>}  </span></li>
<li class="alt">
<span>$</span><span class="attribute">uri</span><span> = </span><span class="attribute-value">isset</span><span>($_SERVER['HTTP_X_REWRITE_URL']) ? $_SERVER['HTTP_X_REWRITE_URL'] : $_SERVER['REQUEST_URI'];  </span>
</li>
<li>
<span>$</span><span class="attribute">content</span><span> = </span><span class="attribute-value">file_get_contents</span><span>("http://www.baidu.com".$uri);  </span>
</li>
<li class="alt"><span> </span></li>
<li>
<span>if($</span><span class="attribute">uri</span><span>=='/'  empty($uri)){  </span>
</li>
<li class="alt"><span>    display($content);  </span></li>
<li><span>}  </span></li>
<li class="alt"><span> </span></li>
<li><span>//删除"来百度推广"链接  </span></li>
<li class="alt">
<span>$</span><span class="attribute">start</span><span> = </span><span class="attribute-value">preg_quote</span><span>("</span><span class="tag"><span class="tag-name">div</span><span> </span><span class="attribute">class</span><span>=\"r ec_bdtg\"</span><span class="tag">></span><span>");  </span></span>
</li>
<li>
<span>$</span><span class="attribute">content</span><span> = </span><span class="attribute-value">preg_replace</span><span>("/".$start."((?!</span><span class="tag"><span class="tag-name">br</span><span class="tag">></span><span>).)*</span><span class="tag"><span class="tag-name">br</span><span class="tag">></span><span>"."/is",'',$content);  </span></span></span>
</li>
<li class="alt"><span> </span></li>
<li><span>//删除左侧竞价  </span></li>
<li class="alt">
<span>$</span><span class="attribute">start</span><span> = </span><span class="attribute-value">"<table>).)*>"<span>;  </span><li>
<span>$</span><span class="attribute">content</span><span> = </span><span class="attribute-value">preg_replace_callback</span><span>("/".$start."((?!</span><span class="tag"><span>\/table</span><span class="tag">></span><span>).)*</span><span class="tag"><span>\/table</span><span class="tag">></span><span>/is","search_result_filter",$content);  </span></span></span>
</li>
<li class="alt"><span> </span></li>
<li>
<span>//删除剩下的多个</span><span class="tag"><span class="tag-name">br</span><span class="tag">></span><span> </span></span>
</li>
<li class="alt">
<span>$</span><span class="attribute">content</span><span> = </span><span class="attribute-value">str_ireplace</span><span>("</span><span class="tag"><span class="tag-name">br</span><span class="tag">></span><span>\n\n</span><span class="tag"><span class="tag-name">br</span><span class="tag">></span><span>",'',$content);  </span></span></span>
</li>
<li>
<span>//删除剩下的多个</span><span class="tag"><span class="tag-name">br</span><span class="tag">></span><span> </span></span>
</li>
<li class="alt">
<span>$</span><span class="attribute">content</span><span> = </span><span class="attribute-value">str_ireplace</span><span>("</span><span class="tag"><span class="tag-name">br</span><span class="tag">/></span><span>                                  \n\n",'',$content);  </span></span>
</li>
<li><span>//删除右侧推广链接  </span></li>
<li class="alt">
<span>$</span><span class="attribute">start</span><span> = </span><span class="attribute-value">preg_quote</span><span>("</span><span class="tag"><span class="tag-name">div</span><span> </span><span class="attribute">id</span><span>=\"ec_im_container\"</span><span class="tag">></span><span>");  </span></span>
</li>
<li>
<span>$</span><span class="attribute">content</span><span> = </span><span class="attribute-value">preg_replace</span><span>("/".$start."((?!</span><span class="tag"><span class="tag-name">style</span><span>).)*"."/is","</span><span class="tag"><span class="tag-name">br</span><span> </span><span class="tag">/></span><span class="tag"></span><span class="tag-name">div</span><span class="tag">></span><span>",$content);  </span></span></span>
</li>
<li class="alt"><span> </span></li>
<li><span>display($content);  </span></li>
<li class="alt"><span>/**  </span></li>
<li><span> * 搜索结果过滤器  </span></li>
<li class="alt"><span> */  </span></li>
<li><span>function search_result_filter($matches){  </span></li>
<li class="alt"><span>    //背景#f5f5f5的是广告  </span></li>
<li>
<span>    if(strpos($matches[0],"</span><span class="attribute">bgcolor</span><span>=\"#f5f5f5\"")) return '';  </span>
</li>
<li class="alt"><span>    //ID4位数的是广告  </span></li>
<li>
<span>    if(preg_match("/</span><span class="tag"><span class="tag-name">table</span><span>(.*?)</span><span class="attribute">id</span><span>=\\\"(\d{4,})\\\"(.*?)</span><span class="tag">></span><span>((?!</span><span class="tag"><span>\/table</span><span class="tag">></span><span>).)*</span><span class="tag"><span>\/table</span><span class="tag">></span><span>/is",$matches[0])){  </span></span></span></span>
</li>
<li class="alt"><span>        return '';  </span></li>
<li><span>    }  </span></li>
<li class="alt"><span>    return $matches[0];  </span></li>
<li><span>}  </span></li>
<li class="alt"><span> </span></li>
<li><span>function display($content) {  </span></li>
<li class="alt"><span>    echo $content;  </span></li>
<li><span>} </span></li>

      <p style="TEXT-INDENT: 2em"><br>
            </p>
<p style="width:100%;text-align:center;margin:10px 0">

<br>
<br>

</p>
<p style="width:100%;text-align:center;margin:10px 0">

            </p>
<p class="clear"></p>

           </table></span>
</li>
</ol>
로그인 후 복사
관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 추천
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿