Skip to content

Commit 9aea154

Browse files
author
Harrison Ifeanyichukwu
committed
docs: improve on project readme docs
1 parent 545a5c5 commit 9aea154

File tree

1 file changed

+67
-48
lines changed

1 file changed

+67
-48
lines changed

README.md

Lines changed: 67 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,26 @@
11
# PHP Feed Parser
22

3-
PHP Feed Parser is a fully integrated syndication feed parser, with support for all major feed types including [RSS](http://cyber.harvard.edu/rss/rss.html), [ATOM](https://tools.ietf.org/html/rfc4287) & [RDF](http://web.resource.org/rss/1.0/spec) feeds.
3+
[![Build Status](https://travis-ci.org/harrison-ifeanyichukwu/php-feed-parser.svg?branch=master)](https://travis-ci.org/harrison-ifeanyichukwu/php-feed-parser)
44

5-
It produces clean, unified parse accross all the three supported feed types. It is configurable, lightweight and fully tested.
5+
PHP Feed Parser is a fully integrated web syndication feed parser. It can successfully parse all the three major syndication feeds which include [RSS](http://cyber.harvard.edu/rss/rss.html), [ATOM](https://tools.ietf.org/html/rfc4287) & [RDF](http://web.resource.org/rss/1.0/spec) feeds.
66

7-
It allows you to parse feeds from three different sources:
7+
It produces clean, unified parse accross all the three supported feed types. It is configurable, lightweight, fully tested and allows one to parse feeds from three different sources that includes **parsing from url, from file or from string**.
88

9-
1. From File using the `parseFromFile($file_abs_path)` method
10-
2. From URL using the `parseFromURL($url)` method
11-
3. From String using the `parseFromString($xml_string)` method
12-
13-
## Install via Composer
9+
## Getting Started
1410

15-
The project is available as a composer package.
11+
**Install via composer**:
1612

1713
```bash
1814
composer require forensic/feed-parser
1915
```
2016

21-
setup your project to require composer's `autoload.php` file.
22-
23-
## Getting Started
17+
Create an instance as shown below:
2418

2519
```php
2620
//include composer autoload.php
2721
require 'vendor/autoload.php';
2822

29-
//use the projects Parser module
23+
//use the project's Parser module
3024
use Forensic\FeedParser\Parser;
3125

3226
//create an instance
@@ -61,11 +55,32 @@ foreach ($items as $item)
6155
}
6256
```
6357

64-
## Setting Parser Options
58+
## Export Feed as JSON
59+
60+
You can also export the parsed feed as json, as shown below. This can also help you view all properties that accessible in the parsed feed.
61+
62+
```php
63+
//create an instance
64+
$parser = new Parser();
65+
66+
//parse yahoo rss news feed
67+
$feed = $parser->parseFromURL('https://www.yahoo.com/news/rss/mostviewed');
68+
69+
header('Content-Type: application/json');
70+
71+
//export whole feed
72+
echo $feed->toJSON();
73+
74+
//export a single item
75+
echo $feed->items[0]->toJSON();
76+
```
77+
78+
## Parser Options
6579

66-
You can pass in some configuration options when creating a Parser instance or even set them later.
80+
The following configuration options can be passed in when creating an instance or set through the designated public methods:
6781

6882
```php
83+
//constructor signature
6984
new Parser(
7085
string $default_lang = 'en',
7186
string $date_template = '',
@@ -74,56 +89,60 @@ new Parser(
7489
);
7590
```
7691

77-
## Modifying options later
92+
- **default_lang**:
7893

79-
You can change options through the appropriate exposed method too.
94+
This option sets the default feed language property to use should there be no language entry found in the xml document.
8095

81-
```php
82-
$parser = new Parser();
96+
```php
97+
$parser = new Parser();
98+
$parser->setDefaultLanguage('fr');
99+
````
83100

84-
//set language
85-
$parser->setLanguage($lang);
101+
- **date_template**:
86102

87-
//set date Template
88-
$parser->setDateTemplate($date_template);
103+
This option sets the date formatter template used when parsing feed date properties such as `lastUpdated`. the default format used is `'jS F, Y, g:i A'`. The formatter template should be a valid php date formatter argument. see [date](http://php.net/manual/en/function.date.php) for details.
89104

90-
//remove styles
91-
$parser->removeStyles(true);
105+
```php
106+
$parser = new Parser();
107+
$parser->setDateTemplate('jS F, y, g:i a');
108+
````
92109

93-
//remove scripts
94-
$parser->removeScripts(true);
95-
```
110+
- **remove_styles**:
96111

97-
## Parser Options Explained
112+
This option states if stylings found in any feed item's content, should be stripped off. The stylings include html `style` element and attribute. Defaults to true.
98113

99-
- **default_lang**: This option sets the default feed language property to use should there be no language entry found in the xml document.
114+
```php
115+
$parser = new Parser();
116+
$parser->removeStyles(true);
117+
```
100118

101-
- **date_template**: This option sets the date formatter template used when parsing feed date properties such as `lastUpdated`. the default format used is `'jS F, Y, g:i A'`. The formatter template should be a valid php date formatter argument. see [date](http://php.net/manual/en/function.date.php) for details.
119+
- **remove_scripts**:
102120

103-
- **remove_styles**: This option states if stylings found in any feed item's content, should be stripped off. The stylings include html `style` element and attribute. Defaults to true.
121+
This option states if any scripting found in any feed item's content, should be stripped off. Scripting includes html `script` element and event handler `on-prefixed` element attributes such as `onclick`. Defaults to true.
104122

105-
- **remove_scripts**: This option states if any scripting found in any feed item's content, should be stripped off. Scripting includes html `script` element and event handler `on-prefixed` element attributes such as `onclick`. Defaults to true.
123+
```php
124+
$parser = new Parser();
125+
$parser->removeScripts(true);
126+
```
106127

107-
### Exporting feed to Array & JSON
128+
## Testing FeedParser
108129

109-
You can export parsed feed to array or json. This can also help you view all properties that are accessible parsed feed.
130+
To locally test or contribute to this project, You should have at least php 7.1, xDebug, composer and npm installed, then ollow the steps below:
110131

111-
```php
112-
//include composer autoload.php
113-
require 'vendor/autoload.php';
132+
**Clone this repo**:
114133

115-
//use the projects Parser module
116-
use Forensic\FeedParser\Parser;
134+
```bash
135+
git clone https://github.com/harrison-ifeanyichukwu/php-feed-parser && php-feed-parser
136+
```
117137

118-
//create an instance
119-
$parser = new Parser();
138+
**Install dependencies**:
120139

121-
//parse yahoo rss news feed
122-
$feed = $parser->parseFromURL('https://www.yahoo.com/news/rss/mostviewed');
140+
```bash
141+
composer install && npm install
142+
```
123143

124-
$feed_array = $feed->toArray();
144+
**Run test**:
125145

126-
//send to front end
127-
header('Content-Type: application/json');
128-
echo $feed->toJSON();
146+
```bash
147+
vendor/bin/phpunit
129148
```

0 commit comments

Comments
 (0)