jQuery怎么读取Array数组添加到html标签,谢谢,下图是源码
$id= $_GET["p"];
$xurl = "https://xxxxxx/?p=".$id;
$str = file_get_contents($xurl);
$vname='#<div class="video__title">(.*?)</div>#';//取出名字
$vimg="/<img data-src=\"(.*?)\"(.*?)>/is";//图片
$vurl='/<a href=\"\/video\/(.*?)\".*?>(.*?)<\/a>/is';//链接
$vtime='#<div class="video-preview__duration">(.*?)</div>#';//视频时长
$vfbtime='/<div class=\"video-preview__novelty\".*?>(.*?)<\/div>/is';//发布时间
$vkan='/<div class=\"video__views\".*?svg>(.*?)<\/div>/is';//发布时间
$vzan='/<div class=\"video__likes video__likes--thumb-up\".*?>(.*?)<\/div>/is';//点赞率
//preg_match_all($vname, $str, $name_matches);
preg_match_all($vimg, $str, $img_matches);
preg_match_all($vurl, $str, $url_matches);
preg_match_all($vtime, $str, $time_matches);
preg_match_all($vfbtime, $str, $fbtime_matches);
preg_match_all($vkan, $str, $kan_matches);
preg_match_all($vzan, $str, $zan_matches);
// 将数组转换为JSON
$arr = array ();
//$arr['name'] = $name_matches[1];
$arr['img'] = $img_matches[1];
$arr['url'] = $url_matches[1];
$arr['time'] = $time_matches[1];
$arr['fbtime'] = $fbtime_matches[1];
$arr['kan'] = $kan_matches[1];
$arr['zan'] = $zan_matches[1];
print_r($arr);
// 把PHP数组转成JSON字符串
$json_string0 = json_encode($arr,JSON_UNESCAPED_UNICODE);
// 写入文件
file_put_contents ( 'test.json' , $json_string0 );
exit;
echo $json_string;
<!DOCTYPE html>
<html>
<head>
<title>jQuery怎么解析Json字符串(Json格式/Json对象)</title>
<script src="js/jquery-2.0.0.min.js"></script>
</head>
<body>
JS循环输出排列(){
<a href="JS获取的链接地址" title=""><img src="JS获取的图片地址" lazy="loaded"></a>
}
最终效果,匹配出所有的数据 如下这样
<a href="http://123" title=""><img src="http://xxx.jpg" lazy="loaded"></a>
<a href="http://456" title=""><img src="http://zzz.jpg" lazy="loaded"></a>
<a href="http://789" title=""><img src="http://sss.jpg" lazy="loaded"></a>
<a href="http://abc" title=""><img src="http://666.jpg" lazy="loaded"></a>
<a href="http://def" title=""><img src="http://333.jpg" lazy="loaded"></a>
................
PHP数组生成的JSON文件代码
Array
(
[img] => Array
(
[0] => https://g.jpeg
[1] => https://c.jpeg
[2] => https://b.jpeg
[3] => https://a.jpeg
[4] => https://2.jpeg
[5] => https://1.jpeg
.........
//共75组数据
)
[url] => Array
(
[0] => 19799780
[1] => 10133200
[2] => 2819740
[3] => 148742748
[4] => 2953797
[5] => 137394488
.........
//共75组数据
)
[time] => Array
(
[0] => 38:49
[1] => 34:54
[2] => 05:37
[3] => 21:24
[4] => 08:13
[5] => 08:07
.........
//共75组数据
)
[fbtime] => Array
(
[0] =>2 年前
[1] =>2 年前
[2] =>11 个月前
[3] => 1 个月前
[4] =>11 个月前
[5] =>11 个月前
.........
//共75组数据
)
[kan] => Array
(
[0] =>
3,586,391
[1] =>
1,954,941
[2] =>
36,102
[3] =>
18,146
[4] =>
19,808
[5] =>
59,112
.........
//共75组数据
)
[zan] => Array
(
[0] => 74%
[1] => 72%
[2] => 100%
[3] => 94%
[4] => 70%
[5] => 94%
.........
//共75组数据
)
)
附加问题图片