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:
- check, is there block with
id="container"
? - 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
精彩评论