PHP code example of whero / simple-html
1. Go to this page and download the library: Download whero/simple-html library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
whero / simple-html example snippets
//字符串加载
$html = \SimpleHtml\SimpleHtml::str_get_html(''<html><body>从字符串中加载html文档演示</body></html>'');
//URL加载
$html = \SimpleHtml\SimpleHtml::str_get_html('https://baidu.com');
//文件加载
$html = \SimpleHtml\SimpleHtml::str_get_html('/tmp/baidu.html');
//查找html文档中的超链接元素
$a = $html->find('a');
//查找文档中第(N)个超链接,如果没有找到则返回空数组.
$a = $html->find('a', 0);
// 查找id为main的div元素
$main = $html->find('div[id=main]',0);
// 查找所有包含有id属性的div元素
$divs = $html->find('div[id]');
// 查找所有包含有id属性的元素
$divs = $html->find('[id]');
//清除使用
$html->clear();
// 调用
$html = \SimpleHtml\HtmlDom::getInit();
$content = $html->strHtml(''<p>从字符串中加载html文档演示</p><p>从字符串中加载html文档演示</p>'');