Yellow Page Publishers


Create [ reviews_get.php ] file for CRON Job that runs daily to save/update reviews.xml -
<?php
ini_set("user_agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
ini_set("max_execution_time", 0);
ini_set("memory_limit", "10000M");

$feed_url = 'http://api2.yp.com/listings/v1/reviews?listingid=1654922&key=xxxxxxxxxx';
$xml = simplexml_load_file($feed_url);
$dom = new DOMDocument();
$dom->load($feed_url);
$dom->save('reviews.xml');
?>


Create [ reviews.php ] file to render pretty XML
<?php
$halfstars = 100 / 5;
$dateformat = "m/d/Y";
    if( ! $xml = simplexml_load_file('[Your Directory]/reviews.xml') )
    {
        echo 'unable to load XML file';
    }
    else
    {
	foreach($xml->reviews->review as $review){
		echo '<div style="display:inline-flex;"><span style="display: block; width: 65px; height: 13px; background: url([Your Directory]/star-rating-sprite.png) 0 0;">
		<span style="display: block; width: '.floatval($review->rating) * $halfstars.'%; height: 13px; background: url([Your Directory]/star-rating-sprite.png) 0 -13px;"></span></span>&nbsp;';
		echo $review->reviewer.',&nbsp;&nbsp;<font style="color:#666;">'.date($dateformat, strtotime($review->reviewDate)).'</font><br /></div><div>';
		echo '<h1>'.$review->reviewSubject.'</h1>';
		echo $review->reviewBody.'<br /></div></p><br />';
	}
    }
?> 

Attorney Walter J. Benson


Reviews unable to load XML file