开发者

Get html block by PHP

We have html page, it has many code inside.

Sometimes it has block #container, sometimes not.

All code of this page is inside $page variable.

How do I:

  1. check, is there block with id="container"?
  2. if html page has #container inside, then get it content开发者_JAVA技巧s of this block and write to a variable $container.

Task should be done by php.


One of the possible ways to solve your problem is to use third party library. Let's say http://simplehtmldom.sourceforge.net/:

$html->load($page);
if ($html->find('#container')) $container = $html->find('#container');


Regexp is your friend here.

Good luck for your html parsing trip

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜