百度站长平台php自动推送简易版

 1 <?php
 2     $str = file_get_contents('url.txt');//将整个文件内容读入到一个字符串中
 3     $str_encoding = mb_convert_encoding($str, 'UTF-8', 'UTF-8,GBK,GB2312,BIG5');//转换字符集(编码)
 4     $arr = explode("\r\n", $str_encoding);//转换成数组
 5 
 6     //去除值中的空格
 7     foreach ($arr as &$row) {
 8         $row = trim($row);
 9     }
10 
11     unset($row);
12     //得到后的数组
13   echo  "<pre>";
14     var_dump($arr);
15   echo  "</pre>";
16 
17 
18 //$urls = array(
19  //   'http://www.example.com/1.html',
20  //   'http://www.example.com/2.html',
21 //);
22 
23 $api = 'http://data.zz.baidu.com/urls?site=www.xxxx.net&token=qpvAQOBkKJr1LePR';
24 $ch = curl_init();
25 $options =  array(
26     CURLOPT_URL => $api,
27     CURLOPT_POST => true,
28     CURLOPT_RETURNTRANSFER => true,
29     CURLOPT_POSTFIELDS => implode("\n", $arr),
30     CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
31 );
32 curl_setopt_array($ch, $options);
33 $result = curl_exec($ch);
34 echo $result;
35 
36 ?>

url.txt放在本php程序目录,和本程序是同一级目录。推送成功显示如下:

 

转载于:https://www.cnblogs.com/secsafe/p/10000573.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值