正则表达式求教 获取网页里的其中一段代码的PHP怎么写?比如截取网页源码中“start” 到 “end”之间的所有代码。函数怎么写? 谢谢,在线等 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 preg_match_all('/start(.*)end/Ui', $str, $matches);print_r($matches); $str="............start......................end........." 真是不好意思,我正则一窍不通。 我要截取</h1> 和 </div> 这2个符号之间的内容怎么写?谢谢楼上的 preg_match_all('/<\/h1>(.*)<\/div>/Ui', $str, $matches);print_r($matches); 似乎不行,我把要截取的贴出来,如下:<div class="post"> <h1></h1><table id="search"> <tr> <th>Heading/<br \> Subheading</th> <th>Stat Suffix</th> <th>Article Description</th> <th>Unit of Quantity</th> <th>General (column 1)</th> <th>Special (column 1)</th> <th>Column 2</th> </tr> <tr> <td> <a href="/heading/9403">9403</a> </td> <td> </td> <td>Other furniture and partsthereof:</td> <td>n/a</td> <td>n/a</td> <td>n/a</td> <td>n/a</td> </tr></table> </div>我希望吧TABLE里的内容截取出来,也就是</h1>和</div>之间的。<table id="search"> <tr> <th>Heading/<br \> Subheading</th> <th>Stat Suffix</th> <th>Article Description</th> <th>Unit of Quantity</th> <th>General (column 1)</th> <th>Special (column 1)</th> <th>Column 2</th> </tr> <tr> <td> <a href="/heading/9403">9403</a> </td> <td> </td> <td>Other furniture and partsthereof:</td> <td>n/a</td> <td>n/a</td> <td>n/a</td> <td>n/a</td> </tr></table> 你给我的代码显示结果是Array ( [0] => Array ( ) [1] => Array ( ) ) <?$str=<<<HTML<div class="post"> <h1></h1><table id="search"> <tr> <th>Heading/<br \> Subheading</th> <th>Stat Suffix</th> <th>Article Description</th> <th>Unit of Quantity</th> <th>General (column 1)</th> <th>Special (column 1)</th> <th>Column 2</th> </tr> <tr> <td> <a href="/heading/9403">9403</a> </td> <td> </td> <td>Other furniture and partsthereof:</td> <td>n/a</td> <td>n/a</td> <td>n/a</td> <td>n/a</td> </tr></table> </div>HTML;preg_match_all('/<div\s+class=\"post\">\s+<h1><\/h1>(.*)<\/div>/Us', $str, $matches);echo $matches[1][0];?> $str = <<<HTML<div class="post"> <h1></h1><table id="search"> <tr> <th>Heading/<br \> Subheading</th> <th>Stat Suffix</th> <th>Article Description</th> <th>Unit of Quantity</th> <th>General (column 1)</th> <th>Special (column 1)</th> <th>Column 2</th> </tr> <tr> <td> <a href="/heading/9403">9403</a> </td> <td> </td> <td>Other furniture and partsthereof:</td> <td>n/a</td> <td>n/a</td> <td>n/a</td> <td>n/a</td> </tr></table> </div>HTML;$str = preg_match_all('/<table.*>[\d\D]*<\/table>/', $str, $matches);echo ($matches[0][0]);/*输出结果:<table id="search"> <tr> <th>Heading/<br \> Subheading</th> <th>Stat Suffix</th> <th>Article Description</th> <th>Unit of Quantity</th> <th>General (column 1)</th> <th>Special (column 1)</th> <th>Column 2</th> </tr> <tr> <td> <a href="/heading/9403">9403</a> </td> <td> </td> <td>Other furniture and partsthereof:</td> <td>n/a</td> <td>n/a</td> <td>n/a</td> <td>n/a</td> </tr></table>*/ php如何发送邮件 请推荐基本网站架构方面的 请求帮助,我的日历控件在FIREFOX上能显示,在IE上不能显示出来?? php连接mysql的问题 去除斜杠 高手帮忙解决个问题 请教:IIS和Apache能否同时使用! 哪位有php 饼图代码 大神啊 PHP 项目路径访问问题请教 用PHP面向对象做了一个计算器,在计算界面输入后,会转到CalProcess.php,但是不显示结果 再问一个正则,不好意思 是否有开发文档范例可以拜读拜读?
print_r($matches);
谢谢楼上的
print_r($matches);
<div class="post">
<h1></h1>
<table id="search">
<tr>
<th>Heading/<br \>
Subheading</th>
<th>Stat Suffix</th>
<th>Article Description</th>
<th>Unit of Quantity</th>
<th>General (column 1)</th>
<th>Special (column 1)</th>
<th>Column 2</th>
</tr>
<tr>
<td>
<a href="/heading/9403">9403</a> </td>
<td>
</td>
<td>Other furniture and partsthereof:</td>
<td>n/a</td>
<td>n/a</td>
<td>n/a</td>
<td>n/a</td>
</tr>
</table> </div>我希望吧TABLE里的内容截取出来,也就是</h1>和</div>之间的。
<table id="search">
<tr>
<th>Heading/<br \>
Subheading</th>
<th>Stat Suffix</th>
<th>Article Description</th>
<th>Unit of Quantity</th>
<th>General (column 1)</th>
<th>Special (column 1)</th>
<th>Column 2</th>
</tr>
<tr>
<td>
<a href="/heading/9403">9403</a> </td>
<td>
</td>
<td>Other furniture and partsthereof:</td>
<td>n/a</td>
<td>n/a</td>
<td>n/a</td>
<td>n/a</td>
</tr>
</table> 你给我的代码显示结果是
Array ( [0] => Array ( ) [1] => Array ( ) )
$str=<<<HTML
<div class="post">
<h1></h1>
<table id="search">
<tr>
<th>Heading/<br \>
Subheading</th>
<th>Stat Suffix</th>
<th>Article Description</th>
<th>Unit of Quantity</th>
<th>General (column 1)</th>
<th>Special (column 1)</th>
<th>Column 2</th>
</tr>
<tr>
<td>
<a href="/heading/9403">9403</a> </td>
<td>
</td>
<td>Other furniture and partsthereof:</td>
<td>n/a</td>
<td>n/a</td>
<td>n/a</td>
<td>n/a</td>
</tr>
</table> </div>
HTML;
preg_match_all('/<div\s+class=\"post\">\s+<h1><\/h1>(.*)<\/div>/Us', $str, $matches);
echo $matches[1][0];
?>
$str = <<<HTML
<div class="post">
<h1></h1>
<table id="search">
<tr>
<th>Heading/<br \>
Subheading</th>
<th>Stat Suffix</th>
<th>Article Description</th>
<th>Unit of Quantity</th>
<th>General (column 1)</th>
<th>Special (column 1)</th>
<th>Column 2</th>
</tr>
<tr>
<td>
<a href="/heading/9403">9403</a> </td>
<td>
</td>
<td>Other furniture and partsthereof:</td>
<td>n/a</td>
<td>n/a</td>
<td>n/a</td>
<td>n/a</td>
</tr>
</table> </div>
HTML;$str = preg_match_all('/<table.*>[\d\D]*<\/table>/', $str, $matches);
echo ($matches[0][0]);
/*
输出结果:
<table id="search">
<tr>
<th>Heading/<br \>
Subheading</th>
<th>Stat Suffix</th>
<th>Article Description</th>
<th>Unit of Quantity</th> <th>General (column 1)</th>
<th>Special (column 1)</th>
<th>Column 2</th>
</tr>
<tr>
<td>
<a href="/heading/9403">9403</a> </td> <td>
</td>
<td>Other furniture and partsthereof:</td>
<td>n/a</td>
<td>n/a</td>
<td>n/a</td>
<td>n/a</td> </tr>
</table>
*/