如题:
<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 .= 'Copy after loginCopy after login用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 .= 'Copy after loginCopy after login
非常感谢版主的回答
测试了一下,果然是有效果的。
不过我还想 超链接那一段能够有具体地址,形如:
<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> </ulCopy after login
版主高手啊,正则 还有 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;Copy after login版主非常强大啊~~~
赞一个~
结贴,哈。Related labels:source:php.cnStatement of this WebsiteThe 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.cnLatest 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:31Latest IssuesRelated TopicsMore>
- Big data platform
- socketpair usage
- What are the video suffixes?
- Formal digital currency trading platform
- What should I do if English letters appear when I turn on the computer and the computer cannot be turned on?
- windows cannot start
- Window function usage
- Is it legal to buy and sell Bitcoin on Huobi.com?
Popular RecommendationsPopular TutorialsMore>
JAVA Beginner's Video Tutorial2566833 Latest DownloadsMore>