<?php
* g! d9 v: G, w3 J3 S1 G# G) K8 X
! W+ s% J' F) V+ n' n// --------------------------------------------------------------------------
+ ]& _& |6 Q- m+ ?8 g// File name : testRegex.php
4 S. M6 N7 l3 ^9 H! a, N8 m// Description : 用正则表达式,取得网页正文部分内容,且仅仅保留表格部分的HTML标签
, M. o, L4 ]: n5 Q3 `4 J// Requirement : PHP4 (
http://www.php.net)
N, K/ r m3 P//
4 ? R+ Z% `9 ^) a# G, W5 O
// Copyright(C), HonestQiao, 2005, All Rights Reserved.
: C _' l- u- \//
; K% M' s. s, t6 L3 L& ? u$ e// Author: HonestQiao (
honestqiao@hotmail.com)
+ R7 |6 S% m% t# d' J//
8 a" `- Q: h. m }* p% N5 K
// --------------------------------------------------------------------------
/ S4 w/ Y" ^6 Y; y! z; C
echo preg_replace('/<!--.*?-->|<(head|title|script|style)[^>]*?>.*?</1>| |(</?(?:table|tbody|th|tr|td))[^>]*?(>)|(?:</(?!table|tbody|th|tr|td))[^>]*?>|(?:<(?!table|tbody|th|tr|td))[^>]*?>/sim', '$2$3', file_get_contents("http://bbs.chinaunix.net"));
$ s' ]$ B2 B( ~3 |3 i- Z9 t! j. s
; i7 a& ?3 H' u! ?+ `; h
?>