You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
6
6
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**.
8
8
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
14
10
15
-
The project is available as a composer package.
11
+
**Install via composer**:
16
12
17
13
```bash
18
14
composer require forensic/feed-parser
19
15
```
20
16
21
-
setup your project to require composer's `autoload.php` file.
22
-
23
-
## Getting Started
17
+
Create an instance as shown below:
24
18
25
19
```php
26
20
//include composer autoload.php
27
21
require 'vendor/autoload.php';
28
22
29
-
//use the projects Parser module
23
+
//use the project's Parser module
30
24
use Forensic\FeedParser\Parser;
31
25
32
26
//create an instance
@@ -61,11 +55,32 @@ foreach ($items as $item)
61
55
}
62
56
```
63
57
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.
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:
67
81
68
82
```php
83
+
//constructor signature
69
84
new Parser(
70
85
string $default_lang = 'en',
71
86
string $date_template = '',
@@ -74,56 +89,60 @@ new Parser(
74
89
);
75
90
```
76
91
77
-
## Modifying options later
92
+
-**default_lang**:
78
93
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.
80
95
81
-
```php
82
-
$parser = new Parser();
96
+
```php
97
+
$parser = new Parser();
98
+
$parser->setDefaultLanguage('fr');
99
+
````
83
100
84
-
//set language
85
-
$parser->setLanguage($lang);
101
+
- **date_template**:
86
102
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.
89
104
90
-
//remove styles
91
-
$parser->removeStyles(true);
105
+
```php
106
+
$parser = new Parser();
107
+
$parser->setDateTemplate('jS F, y, g:i a');
108
+
````
92
109
93
-
//remove scripts
94
-
$parser->removeScripts(true);
95
-
```
110
+
- **remove_styles**:
96
111
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.
98
113
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
+
```
100
118
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**:
102
120
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.
104
122
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
+
```
106
127
107
-
### Exporting feed to Array & JSON
128
+
## Testing FeedParser
108
129
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:
0 commit comments