如题:
<table width="96%"border="0" align="center" cellpadding="4" cellspacing="0"> <tr onMouseOver="this.style.backgroundColor='#EAEAEA'; return true;" onMouseOut="this.style.backgroundColor='transparent';"> <td><a href="news_detail.php?infoId=141" class="link">新闻一</a></td> <td align="right" class="newstime">2014-03-12</td> </tr> <tr onMouseOver="this.style.backgroundColor='#EAEAEA'; return true;" onMouseOut="this.style.backgroundColor='transparent';"> <td><a href="news_detail.php?infoId=140" class="link">新闻二</a></td> <td align="right" class="newstime">2014-02-20</td> </tr></table>
<ul data-role="listview" > <li><a href="#">新闻一 2014-03-12</a></li> <li><a href="#">新闻二 2014-02-20</a></li> </ul>
先匹配。再拼装结果。
$s=<<< TXT<table width="96%"border="0" align="center" cellpadding="4" cellspacing="0"> <tr onMouseOver="this.style.backgroundColor='#EAEAEA'; return true;" onMouseOut="this.style.backgroundColor='transparent';"> <td><a href="news_detail.php?infoId=141" class="link">新闻一</a></td> <td align="right" class="newstime">2014-03-12</td> </tr> <tr onMouseOver="this.style.backgroundColor='#EAEAEA'; return true;" onMouseOut="this.style.backgroundColor='transparent';"> <td><a href="news_detail.php?infoId=140" class="link">新闻二</a></td> <td align="right" class="newstime">2014-02-20</td> </tr></table>TXT; preg_match_all('#]+>\s*]+>(.+?) \s*]+>(.+?)<#s',$s,$m);$html="\n";foreach($m[1] as $k=>$v) $html .= "- $v {$m[2][$k]}
\n";$html .= '
';echo $html;登录后复制 用str_replace要好一点吧
先匹配。再拼装结果。
$s=<<< TXT<table width="96%"border="0" align="center" cellpadding="4" cellspacing="0"> <tr onMouseOver="this.style.backgroundColor='#EAEAEA'; return true;" onMouseOut="this.style.backgroundColor='transparent';"> <td><a href="news_detail.php?infoId=141" class="link">新闻一</a></td> <td align="right" class="newstime">2014-03-12</td> </tr> <tr onMouseOver="this.style.backgroundColor='#EAEAEA'; return true;" onMouseOut="this.style.backgroundColor='transparent';"> <td><a href="news_detail.php?infoId=140" class="link">新闻二</a></td> <td align="right" class="newstime">2014-02-20</td> </tr></table>TXT; preg_match_all('#]+>\s*]+>(.+?) \s*]+>(.+?)<#s',$s,$m);$html="\n";foreach($m[1] as $k=>$v) $html .= "- $v {$m[2][$k]}
\n";$html .= '
';echo $html;登录后复制
非常感谢版主的回答
测试了一下,果然是有效果的。
不过我还想 超链接那一段能够有具体地址,形如:
<ul data-role="listview" > <li><a href="news_detail.php?infoId=141">新闻一 2014-03-12</a></li> <li><a href="news_detail.php?infoId=140">新闻二 2014-02-20</a></li> </ul
登录后复制
版主高手啊,正则 还有 FOREACH能不能大概给个解释,谢谢啊。
高手,分不够还可以再加~~~~
谢谢。
preg_match_all('#<tr[^>]+>\s*<td><a\s*href="(.+?)"[^>]+>(.+?)</a></td>\s*<td[^>]+>(.+?)<#s',$s,$m);$html="<ul data-role=\"listview\" >\n";foreach($m[1] as $k=>$v) $html .= "<li><a href=\"$v\">{$m[2][$k]} {$m[3][$k]}</a></li>\n";$html .= '</ul>';echo $html;登录后复制 版主非常强大啊~~~
赞一个~
结贴,哈。
PHP速学教程(入门到精通)
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
php网站数据库读写分离怎么设置实现_php网站读写分离架构与性能优化配置教程
通过配置MySQL主从复制、修改PHP连接逻辑或使用中间件实现读写分离,可有效降低高并发下数据库负载。具体步骤包括:一、搭建主从架构,主库开启二进制日志并授权复制账号,从库配置server-id并启动复制进程,确保同步状态正常;二、在PHP中定义主从连接参数,编写判断SQL类型的连接类,SELECT等读操作走从库,其他操作走主库;三、引入MaxScale或ProxySQL中间件,配置读写路由规则,使应用无需修改代码即可透明化分流;四、针对主从延迟问题,对写后立即读的场景强制主库查询,检测延迟超阈
2025-11-16 17:36:06
为什么PHP调用图像格式转换函数无效_PHP图像格式转换函数无效问题排查与图像处理库教程
PHP图像格式转换失败通常因GD库未启用、路径错误或资源创建失败。需检查php.ini中extension=gd是否启用,通过php-m或phpinfo()确认GD加载及支持格式;确保源文件存在且可读,使用imagecreatefrom系列函数时验证返回资源非空,处理PNG时设置透明通道;保存图像前确认目标目录可写,输出时设置正确HTTP头并清除输出缓冲;推荐安装ImageMagick扩展作为替代方案,支持更多格式与高级功能;生产环境应结合日志与异常捕获提升稳定性。
2025-11-16 17:34:02
相关专题
更多>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号