无法使用正则表达式捕获html标签! [重复]

Possible Duplicate:
How to parse HTML with PHP?
crawling a html page using php?

Im trying to find a way to find the html tags.

So i tried to use preg_match_all function to find the html tags.

and here is the code what i used :

$code = "<div>This is a test</div>";
preg_match_all("/(<[^<>]+>)([^<>]+)(<[^<>]+>)/",
$code, $matches);
var_dump($matches);

when i used this code, and i try to run it.. the page returned

array(4) { [0]=> array(1) { [0]=> string(25) " This is a test " } [1]=> array(1) { [0]=> string(5) " " } [2]=> array(1) { [0]=> string(14) "This is a test" } [3]=> array(1) { [0]=> string(6) " " } }

as you see in the arrays.. the <div> and </div> didn't detected.

can you help me ? , and tell me where is the problem exactly.

Sorry for my english ..

Thanks,

Please see: RegEx match open tags except XHTML self-contained tags

As Bobince "explains", you shouldn't use regexes to parse HTML.

Since you're using PHP you can check out DOMDocument which allows you to safely parse HTML. Take a look at the reference material, attempt to incorporate DOMDocument into your app and if you still have problems answer a new question or appropriately edit this one.