mekras / atom
Atom 协议支持库
v1.0.0
2016-08-17 14:20 UTC
Requires
- php: >=5.6
- mekras/class-helpers: ^1.3
Requires (Dev)
- phpunit/phpunit: ^5.1.7
- satooshi/php-coveralls: dev-master
This package is auto-updated.
Last update: 2024-08-29 04:25:27 UTC
README
目的
这个库旨在以面向对象的方式与 Atom 文档一起工作。它不包含下载或显示文档的功能。
文档
示例
use Mekras\Atom\Document\FeedDocument; use Mekras\Atom\DocumentFactory; use Mekras\Atom\Exception\AtomException; $xml = file_get_contents('http://example.com/atom'); $factory = new DocumentFactory(); try { $document = $factory->parseXML($xml); } catch (AtomException $e) { die($e->getMessage()); } if ($document instanceof FeedDocument) { $feed = $document->getFeed(); echo 'Feed: ', $feed->getTitle(), PHP_EOL; echo 'Updated: ', $feed->getUpdated()->format('d.m.Y H:i:s'), PHP_EOL; foreach ($feed->getAuthors() as $author) { echo 'Author: ', $author->getName(), PHP_EOL; } foreach ($feed->getEntries() as $entry) { echo PHP_EOL; echo ' Entry: ', $entry->getTitle(), PHP_EOL; if ($entry->getSelfLink()) { echo ' URL: ', $entry->getSelfLink(), PHP_EOL; } else { echo PHP_EOL, (string) $entry->getContent(), PHP_EOL; } } }