日期:2014-05-17 浏览次数:20669 次
array("json","ajax","php+mysql");
$s = <<< TXT ..... <span class="singer" style="width: 95px;"> <a href="artist/001">json</a> </span> ..... <span class="singer" style="width: 95px;"> <a href="artist/002">ajax</a> </span> .... <span class="singer" style="width: 95px;"> <a href="artist/003">php</a> <span>/</span> <a href="artist/004">mysql</a> </span> TXT; preg_match_all("/<span.+<a.+>(.+)</isU", $s, $r); print_r($r[1]);
------解决方案--------------------
$s=<<<html <span class="singer" style="width: 95px;"> <a href="artist/001">json</a> </span> ..... <span class="singer" style="width: 95px;"> <a href="artist/002">ajax</a> </span> <span class="aa" style="width: 95px;"> <a href="artist/002">ajax</a> </span> .... <span class="singer" style="width: 95px;"> <a href="artist/003">php</a> <span>/</span> <a href="artist/004">mysql</a> </span> html; $s= str_replace('<span>/</span>','',$s); preg_match_all('/<span class="singer"[^>]*>(.*)<\/span>/isU',$s,$m); foreach($m[1] as $v){ $v=preg_replace('/<[^>]+>/','',$v,-1,$count); if($count>2) $arr[]=join('+',preg_split("/[\r\n]+/",$v,-1,PREG_SPLIT_NO_EMPTY)); else $arr[]=trim($v); } print_r($arr);