Simple ClickFlow Feed parser sample. This PHP example reads a ClickFlow Json-feed from Linkpulse, converts it to an array and iterates over it while building HTML-markup.
Read more about the ClickFlow feeds here.
If you copy this code, please remember to change the feed url! The one in the sample code are not valid.
<?php
/**
* Sample script for Linkpulse Feeds.
*
* Note: Add a valid feed url in $feedUr.
*
* Onsite Solutions AS - 2012
* http://www.linkpulse.com
* http://www.onsite.no
*/
// Url of a Linkpulse ClickFlow feed in Json-format:
$feedUrl = 'http://feed.linkpulse.com/v1/1234/1234';
$feedString = file_get_contents($feedUrl);
// Make sure the feed is retrieved.
if (!$feedString) {
print 'Error: Could not read file: ' . $feedUrl;
exit;
}
$feedArray = json_decode($feedString);
// Make sure the json feed is converted to an array.
if (is_null($feedArray)) {
print 'Error: Could not convert feed-string to array. ';
exit;
}
$html = '';
foreach ($feedArray->linkpulsefeed as $feed) {
$html .= '<h2>' . $feed->CL . ' clicks</h2>';
$html .= '<h3>From: ' . $feed->from->title . '</h3>';
$html .= '<p>' . $feed->from->description . '</p>';
$html .= '<p>' . $feed->from->url . '</p>';
$html .= '<h3>To: ' . $feed->to->title . '</h3>';
$html .= '<p>' . $feed->to->description . '</p>';
$html .= '<p>' . $feed->to->url . '</p>';
$html .= '<hr />';
}
print $html;
<h2>16387 clicks</h2>
<h3>From: N42 Frontpage</h3>
<p>Get all your news showed as an timeline!</p>
<p>n42.no</p>
<h3>To: VGTV</h3>
<p>Nyheter, sport og underholdning, VGTV serverer alt</p>
<p>www.vgtv.no</p>
<hr />
<h2>12633 clicks</h2>
<h3>From: N42 Frontpage</h3>
<p>Get all your news showed as an timeline!</p>
<p>n42.no</p>
<h3>To: Join the Engadget HD Podcast live on Ustream at 6:30PM ET</h3>
<p>It's Monday, which means it is time for you to listen into the recording booth when the Engadget HD podcast goes to mp3 at</p>
<p>www.engadget.com/2012/10/15/join-the-engadget-hd-podcast-live-on-ustream-at-6-30pm-et</p>
<hr />