如题:
<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 .= "
';echo $html;- $v {$m[2][$k]}
\n";$html .= 'Nach dem Login kopierenNach dem Login kopieren用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 .= "
';echo $html;- $v {$m[2][$k]}
\n";$html .= 'Nach dem Login kopierenNach dem Login kopieren
非常感谢版主的回答
测试了一下,果然是有效果的。
不过我还想 超链接那一段能够有具体地址,形如:
<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> </ulNach dem Login kopieren
版主高手啊,正则 还有 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;Nach dem Login kopieren版主非常强大啊~~~
赞一个~
结贴,哈。Verwandte Etiketten:Erklärung dieser WebsiteDer Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cnNeueste Artikel des Autors
2025-02-26 03:58:14 2025-02-26 03:38:10 2025-02-26 03:17:10 2025-02-26 02:49:09 2025-02-26 01:08:13 2025-02-26 00:46:10 2025-02-25 23:42:08 2025-02-25 22:50:13 2025-02-25 21:54:11 2025-02-25 20:45:11Aktuelle Ausgabenjavascript – Benutzerdefiniertes Datenattribut hinzufügen, wenn in PHP zum zweiten Mal eine Schleife ausgeführt wirdAus 1970-01-01 08:00:00000Wie zentriere ich ein Formular/eine Tabelle mit Feldsätzen in HTML-CSS und halte die Größe konsistent?Aus 1970-01-01 08:00:00000Selektoränderungen in Vue.js: Festlegen ausgewählter Daten für Selektoren und Ereignisselektoren in SchleifenAus 1970-01-01 08:00:00000verwandte ThemenMehr>
So löschen Sie einen Ordner unter Linux
Der Unterschied zwischen get und post
Was tun, wenn Ajax verstümmelte chinesische Zeichen überträgt?
Welche Office-Software gibt es?
Welches OA-System ist besser?
Was sind die 8 Datentypen von Redis?
Methode zum Festlegen des HTML-Bereichs
Tutorial zur Symboleingabe in voller Breite
Beliebte Empfehlungen
Beliebte TutorialsMehr>
![]()
![]()
JAVA-Video-Tutorial für Anfänger2668406![]()
Neueste DownloadsMehr>