CODE CODIFY.CLUB

PHP Pinterest RSS Feed PARSING

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 viral_pinterest() {
  $xml   = new XmlToJson;
  $feed  = json_decode( $xml->Parse( “https://www.pinterest.com/codifyclub/feed.rss/” ) );
  $items = $feed->channel->item;
  foreach( $items as $item ) :
 
   // print_r($item);
   if(is_string($item->title)) echo $item->title;
    echo ‘<br/>’;
   
    echo $item->link;
    echo ‘<br/>’;
 
    $doc = new DOMDocument();
    @$doc->loadHTML($item->description);
    $img_tags = $doc->getElementsByTagName(‘img’);
    foreach ($img_tags as $img_tag) {
       echo $img_path = $img_tag->getAttribute(‘src’);
    }
   

  endforeach;
}

viral_pinterest();

V!ral

Developer, Technology aficionado, Beer Lover and founder of codify.club Network. Who shares a keen interest about website development, health issues, cancer awareness and other fun stuff.

Add comment

Follow us

Don't be shy, get in touch. We love meeting interesting people and making new friends.

Most popular

Most discussed