PHP的HTML解析 wiseparser
wiseparser 是一個 PHP 語言用來解析 HTML 文檔的開發包。
示例代碼:
require_once('treebuilder.php');
$mytree = new Tree();<br>
$mytree->parse_content('<div>Hello world</div>');
// or
$mytree->parse_file('http://www.google.com');
$mytree->parse_file('myfile.htm');
// To print HTML, just do:
echo $mytree;
// For those of you who familiar with HTML::Treebuilder, usage is almost the same. Implemented methods:
// same as HTML::Element
Element->attr($attr, $value = null);
Element->tag($tag = null);
Element->look_down($keys);
Element->traverse($callback, $text_only=false);
Element->push_content($test_or_node, ..);
Element->unshift_content($test_or_node, ..);
Element->detach();
Element->preinsert($test_or_node, ..);
Element->postinsert($test_or_node, ..);
Element->as_HTML();
Element->as_text();
// plus one additional method:
Element->seek_n_destroy($keys); // same as look_down()->detach()->__destruct();
// same as HTML::Treebuilder:
Tree->parse_content($content);
Tree->parse_file($filename_or_url);
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!