Maison >développement back-end >tutoriel php ><tr><td>测试</td><tr>想替换为<LI>测试</LI>求PHP 正则替换,多谢
<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 />
<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 />
$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;