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程序目录,和本程序是同一级目录。推送成功显示如下: