一直以来使用php解析html文档树都是一个难题。Simple HTML DOM parser 帮我们很好地解决了使用 php html 解析 问题。可以通过这个php类来解析html文档,对其中的html元素进行操作 (PHP5+以上版本)。
如何使用php html 解析
上传类文件以后,有三种方式调用这个类:
从url中加载html文档
从字符串中加载html文档
从文件中加载html文档
<?php
// 新建一个Dom实例
$html = new simple_html_dom();
// 从url中加载
$html->load_file('http://www.cnphp.info/php-simple-html-dom-parser-intro.html');
// 从字符串中加载
$html->load('<html><body>从字符串中加载html文档演示</body></html>');
//从文件中加载
$html->load_file('path/file/test.html');
?>
微信公众号
手机浏览(小程序)
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(): Failed to enable crypto in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_1018.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57