tommykent1210 / simple-dom
PHP 的 DOMElement 的包装器。
dev-master
2015-05-17 13:13 UTC
Requires (Dev)
- mockery/mockery: ~0.9
- phpunit/phpunit: ~4.3
This package is not auto-updated.
Last update: 2024-09-28 17:43:48 UTC
README
PHP 的 DOMElement 类的包装器,提供了更友好的 API 以从元素中检索数据。
安装
您可以选择任何您喜欢的安装方式,但我们推荐使用 Composer。
{ "require": { "wpillar/simple-dom": "dev-master" } }
使用
XML
$xml = \Pillar\SimpleDom\Element::xml('<?xml version="1.0"?> <Response> <Items> <Item> <ASIN>1477825274</ASIN> <ItemAttributes> <Title>From the Cradle</Title> <Actor>Brad Pitt</Actor> <Actor>Angelina Jolie</Actor> </ItemAttributes> </Item> </Items> </Response> '); foreach ($xml->getElements('Items') as $item) { $item->getValue('ASIN'); // 1477825274 $item->getElement('ItemAtrributes'); // Pillar\SimpleDom\Element $item->getElement('ItemAttributes')->getValue('Title'); // 'From the Cradle' $item->getElement('ItemAttributes')->getValue('Actor'); // 'Brad Pitt' $item->getElement('ItemAttributes')->getValues('Actor'); // ['Brad Pitt', 'Angelina Jolie'] }
HTML
$html = \Pillar\SimpleDom\Element::html('<!DOCTYPE html> <html> <head> <title>My special website</title> </head> <body> <h1>Welcome to My Special Website!</h1> <p>Hello World!</p> <p>My name is Will</p> </body> </html> '); $html->getElement('head')->getValue('title'); // 'My special website' $html->getElement('body')->getValue('h1'); // 'Welcome to My Special Website' $html->getElement('body')->getValue('p'); // 'Hello World!' $html->getElement('body')->getValues('p'); // ['Hello World!', 'My name is Will'] $html->getElements('p'); // Pillar\SimpleDom\Element[]
贡献
我更喜欢使用 GitHub Flow 来工作。因此,请提交带有您提议的更改的 PR,并说明添加这些更改的理由,包括适当的文档和测试。
这个库旨在遵守 PSR-1、PSR-2 和 PSR-4 标准,请确保您的贡献也遵守这些标准。此外,如果您发现任何违反这些标准的情况,修复它们的 PR 也非常受欢迎。
许可证
MIT 许可证 (MIT)
版权所有 © 2014 Will Pillar
在此特此免费许可任何获得此软件及其相关文档副本(“软件”)的个人,在不受限制的情况下处理该软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本的权利,并允许将软件提供给他人,以便他们可以这样做,但前提是遵守以下条件
上述版权声明和本许可声明应包含在软件的副本或实质部分中。
本软件按“原样”提供,不提供任何形式的保证,明示或暗示,包括但不限于适销性、特定用途的适用性和非侵权性。在任何情况下,作者或版权所有者都不应对任何索赔、损害或其他责任负责,无论是基于合同、侵权或其他方式,源于、源于或与该软件或其使用或其它相关。