> php教程 > php手册 > 본문

批量生成url,该如何处理

WBOY
풀어 주다: 2016-06-06 19:43:06
원래의
858명이 탐색했습니다.

批量生成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
下面是百度短网址接口生成代码
<br />
$ch=curl_init();<br />
curl_setopt($ch,CURLOPT_URL,"http://dwz.cn/create.php");<br />
curl_setopt($ch,CURLOPT_POST,true);<br />
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);<br />
$data=array('url'=>'http://www.baidu.com/');<br />
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);<br />
$strRes=curl_【本文来自鸿网互联 (http://www.68idc.cn)】exec($ch);<br />
curl_close($ch);<br />
$arrResponse=json_decode($strRes,true);<br />
if($arrResponse['status']==0)<br />
{<br />
/**错误处理*/<br />
echo iconv('UTF-8','GBK',$arrResponse['err_msg'])."\n";<br />
}<br />
/** tinyurl */<br />
echo$arrResponse['tinyurl']."\n";<br />
로그인 후 복사

这样子只能生成单条.有没办法以序列批量生成输出.

因为我想要的效果是能批量生成
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就可以
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 추천
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!