php 正則獲取字符串中某段未知子串

<?php 

$i = '<a target="_blank" title="3.29-3.31iPhone11領券立減200元,特惠機型推薦:XSMax低至5799元,XR低至4199元超值推薦!" href="//item.jd.com/100008348542.html" onclick="searchlog(1,100008348542,1,2,>
<a target="_blank" title="3.29-3.31iPhone11領券立減40元,特惠機型推薦:XSMax低至5799元,XR低至4199元超值推薦!" href="//item.jd.com/100008348542.html" onclick="searchlog(1,100008348542,1,2,>';

//讀文件
// $myfile = fopen("jd.html", "r") or die("Unable to open file!");
// $i =  fread($myfile,filesize("jd.html"));
// fclose($myfile);

preg_match_all('/target="_blank" title="(.*?) onclick=/m',$i,$m);
print_r($m);exit;
$d =[];
foreach ($m[0] as  $v) {
	preg_match('/title="(.*?)" href=/m',$v,$m1);
	
	preg_match('/jd.com\/(.*?).html/m',$v,$m2);
	
	$d[]=[
		'name' => $m1[1],
		'good_url' => "https://club.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98&productId=".$m2[1]."&score=3&sortType=5",
		'mid_url' => "https://club.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98&productId=".$m2[1]."&score=2&sortType=5",
		'bid' => "https://club.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98&productId=".$m2[1]."&score=1&sortType=5",
	];
}
print_r(json_encode($d));

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章