开发者

PHP get entire HTML DOM incl. tags

开发者 https://www.devze.com 2023-03-21 04:19 出处:网络
how can I extract the whole html dom element incl. tags via p开发者_如何学运维hp? eg. for: <table id=\"tab\">

how can I extract the whole html dom element incl. tags via p开发者_如何学运维hp? eg. for:

<table id="tab">
    <tr>
        <td>
            foo
        </td>
        <td>
            bar
        </td>
    </tr>
</table>

i do not want only "foo bar" but the whole "<table id="tab"><tr><td>foo</td><td>bar</td></tr></table>" basically, i need a way (funciton) to get the whole tag with inner tags and content via it's id. Something like getTagViaID('http://www.foo.com', 'bar') -> where 'http://www.foo.com' is the link to the page and 'bar' is the id.

Thank you for your time!


You may also want to check out the DOMDocument class provided by PHP:

http://php.net/manual/en/domdocument.loadhtml.php

That'll get the html file loaded

http://www.php.net/manual/en/domxpath.query.php

That'll parse through the HTML file looking for things based on tags. That should get you started. There's additional discussion about getting tag info in this post.

PHP's DOMXPath is stripping out my tags inside the matched text

Hope you get it working!

0

精彩评论

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