php使用正则从指定的文本中截取内容~~ 本帖最后由 hft24dq 于 2011-03-01 18:09:57 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 说明下,由于源文件很长,我剪短了一些。或者请打开链接http://www.24dq.com/?brand-showList.html查看源码,看完整的文本。谢谢大家! $str="";//页面的源码需要转义preg_match("/\<div\sclass\=\"page3\"[.\n]*/",$str,$arr); lz是要匹配<div class="page3"></div>里面内容还是匹配到</html>结尾的啦<?php//匹配<div class="page3"></div>$file=file_get_contents('http://www.24dq.com/?brand-showList.html');$pattern='/<div class="page3">(.*?)<\/div> <div id="Foot">/is';preg_match($pattern,$file,$result);print_r($result[1]);?>匹配到</html><?php$file=file_get_contents('http://www.24dq.com/?brand-showList.html');$pattern='/<div class="page3">(.*?)<\/html>/is';preg_match($pattern,$file,$result);print_r($result[1]);?> 你好,我是想从page3到文件尾部!您的第二段我试了下,很接近了,但是css部分和最后的js调用部分没有取到! $url='http://www.24dq.com/?brand-showList.html';$str=file_get_contents($url);preg_match('/(<div\s*class="page3">[\s\S]*?<\/html>$)/',$str,$match);echo '<pre>';echo $match[1];echo '</pre>';look $pattern='/<div class="page3">([\w\W]*?)<\/html>/';正则这样写,是可以的 文件上传的若干问题 请教如何配置 mysql语句 網站論壇訪問時候出現index目錄是哪方面的錯誤? 请教如何隐藏php的扩展名? 简单的读取文件内容问题。。。。 求一正则表达式相关代码 为什么俺的php无法连接PostgreSQL呢??? oracle8.dll 出错,急。。。。 如何将win2k下的php网站在中软linux3.0下移植? 正则 如何匹配特定字符前的数字 并输出最大的 汇付 天下的接口问题
或者请打开链接http://www.24dq.com/?brand-showList.html查看源码,看完整的文本。谢谢大家!
$str="";//页面的源码需要转义
preg_match("/\<div\sclass\=\"page3\"[.\n]*/",$str,$arr);
<?php
//匹配<div class="page3"></div>
$file=file_get_contents('http://www.24dq.com/?brand-showList.html');
$pattern='/<div class="page3">(.*?)<\/div> <div id="Foot">/is';
preg_match($pattern,$file,$result);
print_r($result[1]);
?>
匹配到</html><?php
$file=file_get_contents('http://www.24dq.com/?brand-showList.html');
$pattern='/<div class="page3">(.*?)<\/html>/is';
preg_match($pattern,$file,$result);
print_r($result[1]);
?>
您的第二段我试了下,很接近了,但是css部分和最后的js调用部分没有取到!
$url='http://www.24dq.com/?brand-showList.html';
$str=file_get_contents($url);
preg_match('/(<div\s*class="page3">[\s\S]*?<\/html>$)/',$str,$match);
echo '<pre>';
echo $match[1];
echo '</pre>';look
正则这样写,是可以的