-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.php
42 lines (33 loc) · 1.29 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
require_once('../vendor/autoload.php');
# 1. Initialize the parser
$parser = new \Sprain\NewsParser\NewsParser();
# 2. Optional - set the cache folder
$parser->setCacheDir('./cache');
# 3. Define your platform. The key is country - platform name
$nzz = $parser->getPlatform('ch-nzz');
# 4. Display the platform's favicon
print '<img src="'.$nzz->getIconUrl().'">';
# 5. Get articles
var_dump($nzz->getRecommendedArticles(5));
# Options: Clear the cache
# $parser->getCache()->clear();
# Options: Disable cache
# $parser->getCache()->disable();
/*
* The output will be something like this:
*
* array (size=3)
* 0 =>
* array (size=2)
* 'url' => string 'http://www.nzz.ch/schweiz/schweizerdeutsch-ist-nicht-minderwertig-1.18352630' (length=76)
* 'title' => string '«Schweizerdeutsch ist nicht minderwertig»' (length=43)
* 1 =>
* array (size=2)
* 'url' => string 'http://www.nzz.ch/meinung/debatte/der-neue-nationalismus-1.18353294' (length=67)
* 'title' => string 'Der neue Nationalismus' (length=22)
* 2 =>
* array (size=2)
* 'url' => string 'http://www.nzz.ch/feuilleton/islamisten-linke-und-neonazis-bilden-allianzen-1.18351849' (length=86)
* 'title' => string 'Islamisten, Linke und Neonazis bilden Allianzen' (length=47)
*/