Home >Backend Development >PHP Tutorial >Baidu Thief: Remove Bidding and Advertising_PHP Tutorial

Baidu Thief: Remove Bidding and Advertising_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:43:011043browse

It functions as mentioned.
The rewrite rules are the same as WordPress.
Compatible with IIS, Apache, and Nginx.
Only one file implements all functions.

<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><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><span class="tag-name">br</span><span class="tag">></span><span>).)*</span><span class="tag"><</span><span class="tag-name">br</span><span class="tag">></span><span>"."/is",,$content);  </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>;  </span>
</li>
<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><span>/table</span><span class="tag">></span><span>).)*</span><span class="tag"><</span><span>/table</span><span class="tag">></span><span>/is","search_result_filter",$content);  </span>
</li>
<li class="alt"><span> </span></li>
<li>
<span>//删除剩下的多个</span><span class="tag"><</span><span class="tag-name">br</span><span class="tag">></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><span class="tag-name">br</span><span class="tag">></span><span>

</span><span class="tag"><</span><span class="tag-name">br</span><span class="tag">></span><span>",,$content);  </span>
</li>
<li>
<span>//删除剩下的多个</span><span class="tag"><</span><span class="tag-name">br</span><span class="tag">></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><span class="tag-name">br</span><span class="tag">/></span><span>                                  

",,$content);  </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><span class="tag-name">div</span><span> </span><span class="attribute">id</span><span>="ec_im_container"</span><span class="tag">></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><span class="tag-name">style</span><span>).)*"."/is","</span><span class="tag"><</span><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>
</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><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><span>/table</span><span class="tag">></span><span>).)*</span><span class="tag"><</span><span>/table</span><span class="tag">></span><span>/is",$matches[0])){  </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>
</ol>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486023.htmlTechArticlefunctions as mentioned. The rewrite rules are the same as WordPress. Compatible with IIS, Apache, and Nginx. Only one file implements all functions. ? php if(isset($_GET[wd])){ $ keywords =$_GET[wd]; } $ uri =...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn