标签:dsc var cad info type tran .com 动态 tao
<?php
header("Content-type:text/html;charset=utf-8");
请求的url
$url = ‘http://dsc.taobaocdn.com/i8/560/330/566337787959/TB1eUs_LlLoK1RjSZFu8qtn0Xla.desc%7Cvar%5Edesc%3Bsign%5Eeba34dfbbd144cadd988b77fa55a102e%3Blang%5Egbk%3Bt%5E1552268585‘;
定义一个数组
$match = array();
curl初始化
$ch =curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
关闭会话
curl_close($ch);
匹配图片路径的正则表达式
$pa = "/(href|src)=([\"|‘]?)([^\"‘>]+.(jpg|JPG|jpeg|JPEG|gif|GIF|png|PNG))/i";
使用preg_match_al执行一个全局正则表达式匹配
preg_match_all($pa, $file_contents, $match);
获取到的是一个二维数组 获取数组的第一个
print_r($match[0]);
// $result = array_reduce($match, ‘array_merge‘,array());
// foreach($result as $k => $v){
// echo "图片url:".$v."\n";
// }
标签:dsc var cad info type tran .com 动态 tao
原文地址:https://www.cnblogs.com/zhizi99/p/10523015.html