Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lian-yue/dom
php html document node parse css level3
https://github.com/lian-yue/dom
Last synced: 30 days ago
JSON representation
php html document node parse css level3
- Host: GitHub
- URL: https://github.com/lian-yue/dom
- Owner: lian-yue
- Created: 2015-06-03T08:04:47.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-07-25T12:24:27.000Z (over 9 years ago)
- Last Synced: 2024-04-21T22:42:53.712Z (7 months ago)
- Language: PHP
- Homepage:
- Size: 219 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# dom
### test
format(true);// 不格式化的
echo $node;// 选择器
// 返回 node 对象的
// 按照id 选择
$node->getElementById('ID');// css选择器 选择一个
$node->querySelector('css选择器');// 返回数组的
// 按照 class 选择
$node->getElementsByClassName('class');// 按照 name 选择
$node->getElementsByName('class');// 按照标签名选择
$node->getElementsByTagName('tagname');// css选择器 选择所有
$node->querySelectorAll('div.qq#xx[attr="xx"]:has(img)');// style 解析
$contents = file_get_contents(__DIR__ . '/style.css');$rule = new DOM\Style\Rule($contents);
// 格式化的
echo $node->format(true);// 不格式化的
echo $node;
// 过滤数据演示// 创建style 过滤 保留 属性 content 开头的前缀 #content- .content- 开头的保留
$filterStyle = new DOM\Filter\Style('content-');
// 创建标签过滤 传入了filterStyle就允许style 标签
$filterTags = new DOM\Filter\Tags($filterStyle);
// 创建属性过滤 传入了filterStyle就允许style 属性
$filterAttributes = new DOM\Filter\Attributes($filterStyle);
/// 解析 dom
$node = new DOM\Node($contents);
// 过滤标签
$filterTags($node);
// 过滤属性
$filterAttributes($node);
// 格式化并输出
echo $node->format(true);?>