批量生成url 下面是百度短网址接口生成代码 $ch=curl_init(); curl_setopt($ch,curlopt_url,http://dwz.cn/create.php); curl_setopt($ch,curlopt_post,true); curl_setopt($ch,curlopt_returntransfer,true); $data=array('url'='http://www.baidu.com/');
批量生成url
下面是百度短网址接口生成代码
$ch=curl_init();
curl_setopt($ch,curlopt_url,http://dwz.cn/create.php);
curl_setopt($ch,curlopt_post,true);
curl_setopt($ch,curlopt_returntransfer,true);
$data=array('url'=>'http://www.baidu.com/');
curl_setopt($ch,curlopt_postfields,$data);
$strres=curl_【本文来自鸿网互联 (http://www.68idc.cn)】exec($ch);
curl_close($ch);
$arrresponse=json_decode($strres,true);
if($arrresponse['status']==0)
{
/**错误处理*/
echo iconv('utf-8','gbk',$arrresponse['err_msg']).\n;
}
/** tinyurl */
echo$arrresponse['tinyurl'].\n;
这样子只能生成单条.有没办法以序列批量生成输出.
因为我想要的效果是能批量生成
www.xxx.cn/?post=1
www.xxx.cn/?post=2
www.xxx.cn/?post=3
......
www.xxx.cn/?post=100
www.xxx.cn/?post=101
序列通通转换成短网址.
------解决思路----------------------
$num = 10;
$url = http://www.xxx.cn?post=;
$sourceary = array();
$destarray = array();
for($i = 0;$i $sourceary[] = $url . $i;
}
foreach ($sourceary as $k=>$v){
$ch=curl_init();
curl_setopt($ch,curlopt_url,http://dwz.cn/create.php);
curl_setopt($ch,curlopt_post,true);
curl_setopt($ch,curlopt_returntransfer,true);
$data=array('url'=> $v);
curl_setopt($ch,curlopt_postfields,$data);
$strres=curl_exec($ch);
curl_close($ch);
$arrresponse=json_decode($strres,true);
if($arrresponse['status']==0){
/**错误处理*/
echo iconv('utf-8','gbk',$arrresponse['err_msg']).\n;
}
$destarray[] = $arrresponse['tinyurl'];
}
//print_r($destarray);
foreach ($destarray as $k=>$v){
echo $v . ;
}
修改$num就可以