真心求教正则表达式
谁帮我把以下代码中,用正则表达式提取以下3个数据呢?
第一:alt="Mexico" 中的 Mexico
第二:7732078 中的 7732078
第三:A 14 中的 A 14
谢谢了。
------解决方案--------------------
- PHP code
<?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);<br><font color="#e78608">------解决方案--------------------</font><br>$re1 = '/alt="[a-zA-Z]*[^"]/i';<br>$re2 = '/<span class="imo">\d*[^\<]/i';<br>$re3 = '/<span class="vessel-name">[a-zA-Z0-9 ]*[^\<]/i';<br>$match ='';<br>preg_match_all($re1, $str, $match);<br>echo '<pre class="brush:php;toolbar:false;">';<br>print_r($match);<br>第一个$re1还有点问题,你在想一想吧<div class="clear">
</div>









