Oggi vedremo come visualizzare in PHP il numero dei lettori che ci seguono via Feed Rss tramite FeedBurner

Per ottenere il numero dei lettori via Feed useremo le API (supportate da hosting PHP5) rilasciate da FeedBurner leggendo al volo un file XML riferito al nostro account

Ecco il codice PHP da inserire nel punto in cui vogliamo visualizzare il numero dei Lettori via Feed RSS

Download Code

<?php
// Set the output readers_count
$readers_count = " [COUNT] Readers via Feed RSS";
// Get feedburner count (Change 'juliusdesign' to own feedburner name)
// Load Feedburner Awareness

$xml = simplexml_load_file
("http://api.feedburner.com/awareness/1.0/GetFeedData?uri=juliusdesign")
or die ("Unable to load XML file!");
// Load Count Readers by Feed Rss
$circulation = $xml->feed->entry['circulation'];
// Replace the [COUNT] in the readers_count with feedcount
$readers_count = str_replace("[COUNT]", $circulation , $readers_count);
// Stamp the Number
echo($readers_count);
?>

La variabile $readers_count contiene il messaggio da visualizzare con il numero [COUNT] dei lettori via Feed RSS

Ora vediamo insieme lo stesso script PHP, ma con la possibilità di rendere Random il messaggio da visualizzare

Download Code

<?php
//Write an Array
$message_feed = array (
"Ho [COUNT] Readers via Feed RSS.",
"Abbonati con i miei [COUNT] Readers via Feed RSS.",
"Il mio blog ha [COUNT] lettori via Feed RSS.",
"Se ho [COUNT] lettori via Feed RSS ci sarà un motivo no?"
);
// Randomize the array
shuffle($message_feed);
// Set the first output readers_count
$readers_count = $message_feed[0];
// Get feedburner count (Change 'juliusdesign' to own feedburner name)
// Load Feedburner Awareness

$xml = simplexml_load_file
("http://api.feedburner.com/awareness/1.0/GetFeedData?uri=juliusdesign")
or die ("Unable to load XML file!");
// Load Count Readers by Feed Rss
$circulation = $xml->feed->entry['circulation'];
// Replace the [COUNT] in the readers_count with feedcount
$readers_count = str_replace("[COUNT]", $circulation , $readers_count);
// Stamp the Number
echo($readers_count);
?>

Per creare vari messagi in modo Random viene creato un Array message_feed in cui inserire i vari messaggi, e inseguito viene “randomizzato” tramite uno shuffle

Autore: Giuliano Ambrosio

Giuliano Ambrosio è un Web Designer Freelance di Torino che ama la grafica e sperimentare tecniche di creatività sul web. Grazie all'esperienza maturata nel campo del web design potrai scoprire i servizi disponibili, oppure guardare i suoi ultimi lavori.