search
Homephp教程php手册批量生成url,该如何处理

批量生成url,该如何处理

Jun 06, 2016 pm 07:43 PM
urlunderdeal withhowbatchgenerateHundred

批量生成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就可以
Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft