可能重复:
How to parse HTML with PHP?
crawling a html page using php?无法使用正则表达式捕获html标签!
我试着找到一种方法找到的HTML标记。
所以我试图用preg_match_all函数来查找html标签。
,这里是我用什么代码:
$code = "<div>This is a test</div>";
preg_match_all("/(<[^<>]+>)([^<>]+)(<[^<>]+>)/",
$code, $matches);
var_dump($matches);
当我用这个代码,我尝试运行它..返回的页面
阵列(4){[0 ] => array(1){[0] => string(25)“ 这是一个测试 ”} [1] => array(1){[0] => string(5)“ ”} [ 2] => array(1){[0] => string(14)“这是一个测试”} [3] => array(1){[0] => string(6)“ ”}}
如您在阵列中看到了..没有检测<div>
和</div>
。
你能帮助我吗? ,并告诉我确切的问题在哪里。
对不起,我的英语..
感谢,
请勿使用正则表达式:http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags –
@Corey Ogburn我想使用正则表达式这是必需的我想要做什么..感谢和抱歉 – Programmer4me
@gpojd这个主题不使用正则表达式..正则表达式是我需要在我的网站做什么.. – Programmer4me