Simple function php
Last active
August 30, 2017 23:07
-
-
Save rhcarlosweb/e2ef3fbd1561806fb5ef91f142a37319 to your computer and use it in GitHub Desktop.
Pinterest Last Pin Feed with PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function nexo_pinterest_feed( $username = null, $countImg = 20 ) { | |
$pin_feed_url = "https://br.pinterest.com/" . $username . "/feed.rss/"; | |
$result_pin = file_get_contents( $pin_feed_url ); | |
$result_pin = simplexml_load_string( $result_pin ); | |
$pin_count = 1; | |
foreach ( $result_pin->channel->item as $item ) { | |
// link | |
$item_link = $item->link; | |
// description | |
$item_description = $item->description; | |
$regex = "/<img((?:[^<>])*)>/"; | |
preg_match( $regex, $item_description, $matches ); | |
echo '<a href="' . $item_link . '" target="_blank">' . $matches[0] . '</a>'; | |
if ( $pin_count == $countImg ) { | |
break; | |
} | |
$pin_count ++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment