panakour/phpdom
最新稳定版本:v0.0.1
Composer 安装命令:
composer require panakour/phpdom
包简介
Some helpers around PHP DOM native classes
README 文档
README
Panakour DOM
This is a PHP package that provides a simple and intuitive API for manipulating DOM elements.
Installation
You can install the package via composer:
composer require panakour/phpdom
Usage
First, you need to create a new instance of the Dom class:
$dom = new Dom('<html><body><p>Hello, World!</p></body></html>');
Getting a list of nodes
You can get a list of nodes with a specific tag name using the getNodeList method:
$images = $dom->getNodeList('img');
This will return a DOMNodeList containing all img elements in the document.
Getting attribute values
You can get the values of a specific attribute for all nodes with a specific tag name using the getAttributesValue method:
$imgSrc = $dom->getAttributesValue('img', 'src');
Replacing attributes
You can replace the attributes of all nodes with a specific tag name using the replaceAttributes method:
$dom->replaceAttributes('img', [ ['src' => 'new-src.jpg', 'alt' => 'New image'] ]);
This will replace the src and alt attributes of all img elements in the document.
Removing elements
You can remove all nodes with a specific tag name using the removeElementsAndItsContent method:
$dom->removeElementsAndItsContent(['img']);
This will remove all img elements from the document.
Explore More
Explore additional features and use cases in the unit tests found in /tests/DomTest.php.
统计信息
- 总下载量: 218
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-12-16