<tr><td>测试</td><tr>想替换为<LI>测试</LI>求PHP 正则替换,多谢
Release: 2016-06-13 11:51:23
Original
1082 people have browsed it
测试 |
想替换为测试求PHP 正则替换,谢谢。
如题:
测试 |
想替换为测试求PHP 正则替换,谢谢。
因为我的HTML代码如下:
<br /><table width="96%"border="0" align="center" cellpadding="4" cellspacing="0"><br /><br /> <tr onMouseOver="this.style.backgroundColor='#EAEAEA'; return true;" onMouseOut="this.style.backgroundColor='transparent';"><br /> <td><a href="news_detail.php?infoId=141" class="link">新闻一</a></td><br /> <td align="right" class="newstime">2014-03-12</td><br /> </tr><br /><br /> <tr onMouseOver="this.style.backgroundColor='#EAEAEA'; return true;" onMouseOut="this.style.backgroundColor='transparent';"><br /> <td><a href="news_detail.php?infoId=140" class="link">新闻二</a></td><br /> <td align="right" class="newstime">2014-02-20</td><br /> </tr><br /></table><br /><br /><br />
Copy after login
想替换成
<br /><ul data-role="listview" ><br /> <li><a href="#">新闻一 2014-03-12</a></li><br /> <li><a href="#">新闻二 2014-02-20</a></li><br /> <br /></ul><br />
Copy after login
------解决方案--------------------
先匹配。再拼装结果。
$s=<<< TXT<br /><br /><table width="96%"border="0" align="center" cellpadding="4" cellspacing="0"><br /><br /> <tr onMouseOver="this.style.backgroundColor='#EAEAEA'; return true;" onMouseOut="this.style.backgroundColor='transparent';"><br /> <td><a href="news_detail.php?infoId=141" class="link">新闻一</a></td><br /> <td align="right" class="newstime">2014-03-12</td><br /> </tr><br /><br /> <tr onMouseOver="this.style.backgroundColor='#EAEAEA'; return true;" onMouseOut="this.style.backgroundColor='transparent';"><br /> <td><a href="news_detail.php?infoId=140" class="link">新闻二</a></td><br /> <td align="right" class="newstime">2014-02-20</td><br /> </tr><br /></table><br />TXT;<br /> preg_match_all('#<tr[^>]+>\s*<td><a[^>]+>(.+?)</a></td>\s*<td[^>]+>(.+?)<#s',$s,$m);<br /><br />$html="<ul data-role=\"listview\" >\n";<br />foreach($m[1] as $k=>$v) $html .= "<li><a href=\"#\">$v {$m[2][$k]}</a></li>\n";<br />$html .= '</ul>';<br />echo $html;
Copy after login
------解决方案--------------------
用str_replace要好一点吧
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31