日期:2014-05-17 浏览次数:20434 次
<?php $str=<<<HTML <div class="items"> <a class="imo-block" href="/site/details?imo=7732078"> <img title="Mexico" src="/images/flags/mx.png" alt="Mexico" /> <span class="imo">7732078</span> <br/> <span class="vessel-name">A 14</span> </a> <a class="imo-block" href="/site/details?imo=7528398"> <img title="Mexico" src="/images/flags/mx.png" alt="China" /> <span class="imo">7528398</span> <br/> <span class="vessel-name">A 15</span> </a> </div> HTML; preg_match_all('/alt="(.*?)"|class="imo">(.*?)<|vessel-name">(.*?)</i',$str,$matchs); print_r($matchs);
------解决方案--------------------
$re1 = '/alt="[a-zA-Z]*[^"]/i';
$re2 = '/<span class="imo">\d*[^\<]/i';
$re3 = '/<span class="vessel-name">[a-zA-Z0-9 ]*[^\<]/i';
$match ='';
preg_match_all($re1, $str, $match);
echo '<pre>';
print_r($match);
第一个$re1还有点问题,你在想一想吧