Home > php教程 > php手册 > php curl 检查百度是否收录文章的例子

php curl 检查百度是否收录文章的例子

WBOY
Release: 2016-05-25 16:45:30
Original
939 people have browsed it

发的文章如果我每一篇都是手工查的话是非常的累的,这里可以利用一个简单的php函数来帮我们实现自动检测,下面我们就利用php curl来做一个模仿用户去访问百度的wgbb例子,希望此例子对各位会有所帮助.

只要在主题的function.php里添加以下代码就可以实现啦~PHP实例代码如下:

<?php
function d4v($url) {
    $url = &#39;http://www.baidu.com/s?wd=&#39; . $url;
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $rs = curl_exec($curl);
    curl_close($curl);
    if (!strpos($rs, &#39;没有找到&#39;)) {
        return 1;
    } else {
        return 0;
    }
}
add_filter(&#39;the_content&#39;, &#39;baidu_submit&#39;);
function baidu_submit($content) {
    if (is_single() && current_user_can(&#39;manage_options&#39;)) if (d4v(get_permalink()) == 1) $content = "<p align=right>百度已收录(仅管理员可见)</p>" . $content;
    else $content = "<p align=right><b><a style=color:red target=_blank href=http://zhanzhang.baidu.com/sitesubmit/index?sitename=" . get_permalink() . ">百度未收录!点击此处提交</a></b>(仅管理员可见)</p>" . $content;
    return $content;
}
?>
Copy after login


本文地址:

转载随意,但请附上文章地址:-)

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template