Skip to content

Instantly share code, notes, and snippets.

@moimikey
Created February 26, 2013 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moimikey/5042795 to your computer and use it in GitHub Desktop.
Save moimikey/5042795 to your computer and use it in GitHub Desktop.
latest pinterest feed using their simple rss feed transcoded to json.
<?php
class XmlToJson {
public function Parse( $url ) {
$fileContents = file_get_contents( $url );
$fileContents = str_replace( array(
"\n",
"\r",
"\t"
), '', $fileContents );
$fileContents = trim( str_replace( '"', "'", $fileContents ) );
$simpleXml = simplexml_load_string( $fileContents );
$json = json_encode( $simpleXml );
return $json;
}
}
function msh_pinterest() {
$xml = new XmlToJson;
$feed = json_decode( $xml->Parse( "http://pinterest.com/pinterest/feed.rss" ) );
$items = $feed->channel->item;
foreach( $items as $item ) :
printf( '%s', $item->description );
endforeach;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment