file_get_contents第二波!正则匹配很欢乐
问题是这样的 file_get_contents 出来的内容是这样
.....
json
.....
ajax
....
php
/
mysql
我想得到的结果是
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
array("json","ajax","php+mysql");
$s =
<a href="artist/001">json</a>
.....
<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.>(.+)", $s, $r);
print_r($r[1]);
<br><font color="#e78608">------解决方案--------------------</font><br><dl class="code">PHP code<pre class="brush:php;toolbar:false;">
$s=
<a href="artist/001">json</a>
.....
<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">]*>(.*)/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); <div class="clear"></div></span>
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号