真心求教正则表达式
谁帮我把以下代码中,用正则表达式提取以下3个数据呢?
第一:alt="Mexico" 中的 Mexico
第二:7732078 中的 7732078
第三:A 14 中的 A 14
<?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"><script src="https://www.php.cn/hezuo/f220a8ffcae8732bbc8e3d8f7f36834b.js"></script> <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>
HTML;
preg_match_all('/alt="(.*?)"|class="imo">(.*?)(.*?)',$str,$matchs);
print_r($matchs);
<br><font color="#e78608">------解决方案--------------------</font><br>
$re1 = '/alt="[a-zA-Z]*[^"]/i';<br>$re2 = '/<span class="imo">\d*[^\$re3 = '/<span class="vessel-name">[a-zA-Z0-9 ]*[^\$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>
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号