Include part of a PHP file - php

I have a PHP file (Region.php) and an excerpt of my code is:
<?php
/** Create HTTP POST */
$country = 'Australia';
$area = htmlspecialchars($_POST["area"]);
$seek = '<parameters>
<row><param>COUNTRY</param><value>'. $country .'</value></row>
<row><param>AREA</param><value>'. $area .'</value></row>
</parameters>';
$postdata = http_build_query(
array(
'DistributorKey' => '201201100935',
'CommandName' => 'GetCities',
'CommandParameters' => $seek)
);
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata)
);
/** Get string output of XML (In URL instance) */
$context = stream_context_create($opts);
$result = file_get_contents('http://national.atdw.com.au/soap/AustralianTourismWebService.asmx/CommandHandler?', false, $context);
/** Change encoding from UTF-16 to Unicode (UTF-8)
Parse unstructured tags */
$result = str_replace('<?xml version="1.0" encoding="utf-8"?>', '', $result);
$result = str_replace('<string xmlns="http://tempuri.org/soap/AustralianTourismWebService">', '', $result);
$result = str_replace('</string>', '', $result);
$result = str_replace('utf-16', 'utf-8', $result);
$result = simplexml_load_string(trim(html_entity_decode($result)), 'SimpleXMLElement');
/** Instantiate Loop */
foreach ($result->area as $entry) {
echo $entry->attributes()->area_name . "<br /><br />";
}
foreach ($result->area->city as $entry) {
$pna = htmlspecialchars_decode($entry->attributes()->suburb_city_postal_code, ENT_QUOTES);
$pna = str_replace("'", "''", $pna);
$str = htmlspecialchars_decode($entry->attributes()->attribute_id_status, ENT_QUOTES);
$str = str_replace("'", "''", $str);
echo $pna. "<br />";
echo $str . "<br />";
echo (string)$entry . "<br /><br />";
}
?>
I have another PHP file (Houses.php) but I need only the value of $entry->attributes()->area_name in the Houses.php file. Excerpt of my code in Houses.php:
<?php
require_once 'Region.php';
/** Create HTTP POST */
$accomm = 'ACCOMM';
$region = '('$entry->attributes()->area_name')';
$page = '10';
---- some code ---
?>
I keep getting errors because it is executes the entire Region.php file whereas I only need the value of the attribute().
Please how can I fix this.
Thanks

I can interpret comments as this, as you cannot include only part of a PHP file:
Create a file header.inc.php, not header.inc for security, as one can download a .inc as source file by bad config, but not .php, as executed by apache2 :
<?php
/** Create HTTP POST */
$country = 'Australia';
$area = htmlspecialchars($_POST["area"]);
$seek = '<parameters>
<row><param>COUNTRY</param><value>'. $country .'</value></row>
<row><param>AREA</param><value>'. $area .'</value></row>
</parameters>';
$postdata = http_build_query(
array(
'DistributorKey' => '201201100935',
'CommandName' => 'GetCities',
'CommandParameters' => $seek)
);
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata)
);
/** Get string output of XML (In URL instance) */
$context = stream_context_create($opts);
$result = file_get_contents('http://national.atdw.com.au/soap/AustralianTourismWebService.asmx/CommandHandler?', false, $context);
/** Change encoding from UTF-16 to Unicode (UTF-8)
Parse unstructured tags */
$result = str_replace('<?xml version="1.0" encoding="utf-8"?>', '', $result);
$result = str_replace('<string xmlns="http://tempuri.org/soap/AustralianTourismWebService">', '', $result);
$result = str_replace('</string>', '', $result);
$result = str_replace('utf-16', 'utf-8', $result);
$result = simplexml_load_string(trim(html_entity_decode($result)), 'SimpleXMLElement');
?>
Shorten the Region.php file:
<?php
require_once "header.inc.php";
/** Instantiate Loop */
foreach ($result->area as $entry) {
echo $entry->attributes()->area_name . "<br /><br />";
}
foreach ($result->area->city as $entry) {
$pna = htmlspecialchars_decode($entry->attributes()->suburb_city_postal_code, ENT_QUOTES);
$pna = str_replace("'", "''", $pna);
$str = htmlspecialchars_decode($entry->attributes()->attribute_id_status, ENT_QUOTES);
$str = str_replace("'", "''", $str);
echo $pna. "<br />";
echo $str . "<br />";
echo (string)$entry . "<br /><br />";
}
?>
In House.php:
<?php
require_once 'header.inc.php';
/** Create HTTP POST */
$accomm = 'ACCOMM';
$region = "";
foreach ($result->area as $entry) {
$region = $entry->attributes()->area_name;
break;
}
$page = '10';
---- some code ---
?>
All the tree files must reside in the same directory/folder.

Organize your code into functions:
myfuncts.php
function fn1() {
...stuff...
...stuff...
} // fn1()
function fn2() {
...things...
...things...
} // fn2()
Then you can use them by simply calling:
require("functions.php");
fn1();
fn3();

Related

Twitter stream api print out statuses

I have the following code
<?php
/*
This is an app to search tiwtter statuses.
*/
function queryTwitter($search)
{
$url = "https://api.twitter.com/1.1/search/tweets.json";
if($search != "")
$search = "#".$search;
$query = array( 'count' => 100, 'q' => urlencode($search), "result_type" => "recent");
$oauth_access_token = "XXXX";
$oauth_access_token_secret = "xxxx";
$consumer_key = "xxxx";
$consumer_secret = "xxxx";
$oauth = array(
'oauth_consumer_key' => $consumer_key,
'oauth_nonce' => time(),
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_token' => $oauth_access_token,
'oauth_timestamp' => time(),
'oauth_version' => '1.0');
$base_params = empty($query) ? $oauth : array_merge($query,$oauth);
$base_info = buildBaseString($url, 'GET', $base_params);
$url = empty($query) ? $url : $url . "?" . http_build_query($query);
$composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);
$oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
$oauth['oauth_signature'] = $oauth_signature;
$header = array(buildAuthorizationHeader($oauth), 'Expect:');
$options = array( CURLOPT_HTTPHEADER => $header,
CURLOPT_HEADER => false,
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false);
$feed = curl_init();
curl_setopt_array($feed, $options);
$json = curl_exec($feed);
curl_close($feed);
return json_decode($json);
}
function buildBaseString($baseURI, $method, $params)
{
$r = array();
ksort($params);
foreach($params as $key=>$value){
$r[] = "$key=" . rawurlencode($value);
}
return $method."&" . rawurlencode($baseURI) . '&' . rawurlencode(implode('&', $r));
}
function buildAuthorizationHeader($oauth)
{
$r = 'Authorization: OAuth ';
$values = array();
foreach($oauth as $key=>$value)
$values[] = "$key=\"" . rawurlencode($value) . "\"";
$r .= implode(', ', $values);
return $r;
}
// This is where I want to break down the object to an array and have it print out each individual tweet
function displayTweets($object){
$myArray = json_decode(json_encode($object), true);
//print_r($myArray);
foreach ($myArray as $tweet){
print "Status: ";
$array = print_r($tweet,true);
print $array['text'];
print "<br>";
}
}
?>
<html>
<head>
</head>
<body>
Search here for twitter statuses.
<input type='text'>
<br>
<?php
$search = queryTwitter("dbz");
//print_r($search);
displayTweets($search);
?>
</body>
</html>
I am trying to put out a status found like this...
print $tweet['text'];
I am not sure on how to convert the $search object to an array where I can print $tweet['text'] or print $tweet['location'];
How do I convert the object created by the function queryTwitter($search) to a printable array. I also tried to foreach the object and print out $tweet->text and it didn't work. When I use print_r($object) it prints out the information. How can I complete the displayTweets function?
I figured it out.
here is the solution in code.
function displayTweets($object){
$myArray = json_decode(json_encode($object), true);
//$myArray = json_encode($object);
//echo print_r($myArray["statuses"][0]);
foreach ($myArray["statuses"] as $tweet){
echo "User :";
echo $tweet['user']['screen_name'];
echo "<br>";
echo $tweet['text'];
echo "<br>";
}
}

php parse xml from url

http://api.hostip.info/?ip=87.14.94.152
From this link (xml) i am tried to retrive countryName and countryAbbrev like this:
$url = 'http://api.hostip.info/?ip=87.14.94.152';
$xml = simplexml_load_file($url) or die("feed not loading");
$Country = $xml->gml['featureMember']->Hostip->countryName;
echo $Country;
echo 'BREAK HTML';
echo "-----";
echo "// "; var_dump($xml); echo " //";
but $Country is blank, any idea about?
thanks in advance
Try this not like an answer, but, just another way to do the same:
$data = file_get_contents('http://api.hostip.info/get_html.php?ip=87.14.94.152&position=true');
$arrayofdata = explode("\n", $data);
$country = explode(":", $arrayofdata[0]);
$count = explode(" ", $country[1]);
echo "Country Name: ".$count[1]."</br>"; //Prints ITALY
echo "Country Abbv: ".trim($count[2],"()"); //Prints IT
The position=true url part, it's just in case that you want to retrieve the coordinates.
Cheers ;)
Try this:
$url = 'http://api.hostip.info/?ip=87.14.94.152';
$xml = simplexml_load_file($url) or die("feed not loading");
$fm=$xml->xpath('//gml:featureMember');
print_r($fm[0]->Hostip->countryName);
Make a local copy of the xml and it will work. Just tested this and got the data back:
$url = 'http://api.hostip.info/?ip=87.14.94.152';
$data = file_get_contents($url);
$xml = simplexml_load_file($data) or die("feed not loading");
The countryName node is nested in a deeper level. You can use the children() method to access attributes with colon. Here's how you can get the country name:
$countryName = (string) $xml->children('gml', true)
->featureMember->children('', true)
->Hostip->countryName; // => ITALY
You could also use an XPath expression to retrieve the country name. This is easier:
$hostip = $xml->xpath('//Hostip');
$countryName = $hostip[0]->countryName; // => ITALY
$countryAbbrev = $hostip[0]->countryAbbrev; // => IT
protected function getCountryNameFromIP()
{
$ip = $_SERVER['REMOTE_ADDR'];
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"Cookie: foo=bar\r\n"
)
);
$context = stream_context_create($opts);
$answerIP = #file_get_contents("http://api.ipinfodb.com/v3/ip-country/?key=4b585e37503a519a408dc17878e6ec04fa963e1b946c567722538d9431c2d5cb&format=xml&ip=$ip" ,false,$context);
if(isset($answerIP) && $answerIP !="")
{
$theResJ = simplexml_load_string($answerIP);
$last_login_ip_cn = $theResJ->countryName;
/**
* $last_login_ip_cc = $theResJ->countryCode;
* $last_login_ip_rc = $theResJ->regionCode;
* $last_login_ip_rn = $theResJ->regionName;
* $last_login_ip_cp = $theResJ->cityName;
* $last_login_ip_lat = $theResJ->latitude;
* $last_login_ip_lng = $theResJ->longitude;
* $last_login_zip_code= $theResJ->zipCode;
*/
}
else
{
$last_login_ip_cn = "";
/**
* $last_login_ip_cc = "";
* $last_login_ip_rc = "";
* $last_login_ip_rn = "";
* $last_login_ip_cp = "";
* $last_login_ip_lat = "";
* $last_login_ip_lng = "";
* $last_login_zip_code= "";
*/
}
return $last_login_ip_cn;
}
I hope it helps you
I agree. I just tried both answers and got good results. Here is the test code I just ran:
<?php
$url = 'http://api.hostip.info/?ip=87.14.94.152';
// $data = file_get_contents($url);
$xml = simplexml_load_file($url) or die("feed not loading");
// $Country = $xml->gml['featureMember']->Hostip->countryName;
// echo $Country;
echo 'BREAK HTML';
echo "-----";
echo "// "; var_dump($xml); echo " //<br/>";
?><br/><?php
var_dump($xml->gml);
?><br/><?php
print_r($xml);
?><br/><?php
var_dump((string) $xml->gml->featureMember->Hostip->countryName);
?><br/><?php
echo $xml->gml['featureMember']->Hostip->countryName;
$Country = (string) $xml->children('gml', true)
->featureMember->children('', true)
->Hostip->countryName; // => ITALY
echo $Country;
$fm=$xml->xpath('//gml:featureMember');
print_r($fm[0]->Hostip->countryName);
and here are the results output:
BREAK HTML-----// object(SimpleXMLElement)#1 (1) { ["#attributes"]=> array(1) { ["version"]=> string(5) "1.0.1" } } //
object(SimpleXMLElement)#2 (0) { }
SimpleXMLElement Object ( [#attributes] => Array ( [version] => 1.0.1 ) )
string(0) ""
ITALYSimpleXMLElement Object ( [0] => ITALY )

Delete a tweet using the twitter-async library by searching for the tweet?

I'm looking for some help deleting a tweet using twitter-async from https://github.com/jmathai/twitter-async by I guess searching for the tweet?
If we try the following code we can post to twitter
try {
$twitter->post_statusesUpdate(array('status' => $tweet));
} catch (EpiTwitterForbiddenException $e) {
$msg = json_decode($e->getMessage());
if ($msg->error != 'Status is a duplicate.') {
//throw $e;
}
}
https://dev.twitter.com/docs/api/1.1/post/statuses/destroy/%3Aid
However, if it's ran twice the second time it will return that it's a duplicate tweet... or if it was tweeted a few tweets prior it will again return that it's a duplicate tweet.
How can I either search for and then delete or directly delete the duplicate tweet and then tweet the exact message again (putting it to top/latest tweet)
Any ideas?
To do what you want, you have to:
1st: search the tweets of the user, and interpret its json to get the id of a repeated tweet if there is one. (notice that when comparing the text you shall use the php function htmlspecialchars() because there are special characters that are stored in twitter as HTML entities [ref.]);
2nd: remove the repeated tweet if it exists;
3rd: (re-)post the tweet.
(optionally you can add a 0th step, which would be to try a normal submission of the tweet, and advance to the other steps only if you have an error, it's up to you.)
Here you have a code that makes these requests and interpret the json of the search, etc.:
$settings = array(
'oauth_access_token' => "...",
'oauth_access_token_secret' => "...",
'consumer_key' => "...",
'consumer_secret' => "..."
);
$API = new twitter_API($settings);
$tweet_text = '>>testing the twitter API-1.1...';
## search the list of tweets for a duplicate...
$url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
$json = $API->make_request($url, "GET");
$twitter_data = json_decode($json);
$id_str = null;
foreach ($twitter_data as $item){
$cur_text = $item->text;
if (strcmp($cur_text, htmlspecialchars($tweet_text))==0){
$id_str = $item->id_str;
echo "found a duplicate tweet with the id: " . $id_str . "<br /><br />";
}
}
## remove the duplicate, if there is one...
if ($id_str){
$url = "https://api.twitter.com/1.1/statuses/destroy/" . $id_str . ".json";
$json = $API->make_request($url, "POST");
echo $json . '<br /><br />';
}
## post the tweet
$url = "https://api.twitter.com/1.1/statuses/update.json";
$postfields = array(
'status' => $tweet_text
);
$json = $API->make_request($url, "POST", $postfields);
echo $json . '<br /><br />';
This code uses the class twitter_API, which is an adaptation from the answers in [ref.]. You can use this class, or replace the callings to their functions by the functions of twitter-async.
class twitter_API
{
private $oauth_access_token;
private $oauth_access_token_secret;
private $consumer_key;
private $consumer_secret;
protected $oauth;
public function __construct(array $settings){
if (!in_array('curl', get_loaded_extensions())){
echo 'you need to install cURL!';
exit();
}
$this->oauth_access_token = $settings['oauth_access_token'];
$this->oauth_access_token_secret = $settings['oauth_access_token_secret'];
$this->consumer_key = $settings['consumer_key'];
$this->consumer_secret = $settings['consumer_secret'];
}
function build_base_string($base_URI, $method, $params){
$r = array();
ksort($params);
foreach($params as $key=>$value){
$r[] = "$key=" . rawurlencode($value);
}
return $method . "&" . rawurlencode($base_URI) . '&' . rawurlencode(implode('&', $r));
}
function build_authorization_header($oauth){
$r = 'authorization: oauth ';
$values = array();
foreach ($oauth as $key=>$value)
$values[] = "$key=\"" . rawurlencode($value) . "\"";
$r .= implode(', ', $values);
return $r;
}
function make_request($url, $type, $args=null){
$this->oauth = array( 'oauth_consumer_key' => $this->consumer_key,
'oauth_nonce' => time(),
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_token' => $this->oauth_access_token,
'oauth_timestamp' => time(),
'oauth_version' => '1.0');
if (($type=="GET") && (!is_null($args))){
$getfields = str_replace('?', '', explode('&', $args));
foreach ($getfields as $field){
$field_strs = explode('=', $field);
$this->oauth[$field_strs[0]] = $field_strs[1];
}
}
$base_info = $this->build_base_string($url, $type, $this->oauth);
$composite_key = rawurlencode($this->consumer_secret) . '&' . rawurlencode($this->oauth_access_token_secret);
$oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
$this->oauth['oauth_signature'] = $oauth_signature;
// make request
$header = array($this->build_authorization_header($this->oauth), 'expect:');
$options = array( CURLOPT_HTTPHEADER => $header,
CURLOPT_HEADER => false,
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false);
if ($type=="POST"){
if (is_null($args)){
$args = array();
}
$options[CURLOPT_POSTFIELDS] = $args;
}
else if (($type=="GET") && (!is_null($args))){
$options[CURLOPT_URL] .= $args;
}
$feed = curl_init();
curl_setopt_array($feed, $options);
$json = curl_exec($feed);
curl_close($feed);
return $json;
}
}

Flickr API returning duplicate images

I'm trying to get images from flickr using the Flickr API and I'm having trouble figuring out how to get only unique images. I've already reviewed the arguments for the specific method that I'm using and here's what I came up with:
<?php
class Flickr {
private $flickr_key;
private $flickr_secret;
private $format = 'json';
public function __construct( $flickr_key, $flickr_secret ) {
$this->flickr_key = $flickr_key;
$this->flickr_secret = $flickr_secret;
}
public function searchPhotos( $query = '', $tags = '' ) {
$urlencoded_tags = array();
$tags_r = explode(',', $tags);
foreach($tags_r as $tag){
$urlencoded_tags[] = urlencode($tag);
}
$url = 'http://api.flickr.com/services/rest/?';
$url .= 'method=flickr.photos.search';
$url .= '&text=' . urlencode($query);
$url .= '&tags=' . implode(',', $urlencoded_tags);
$url .= '&sort=relevance';
$url .= '&safe_search=1';
$url .= '&content_type=4';
$url .= '&api_key=' . $this->flickr_key;
$url .= '&format=' . $this->format;
$url .= '&per_page=10';
$url .= '&media=photos';
$url .= '&privacy_filter=1';
$result = #file_get_contents( $url );
$json = substr( $result, strlen( "jsonFlickrApi(" ), strlen( $result ) - strlen( "jsonFlickrApi(" ) - 1 );
$photos = array();
$data = json_decode( $json, true );
if($data['stat'] != 'fail'){
$photos = $data['photos']['photo'];
return $photos;
}else{
return false;
}
}
}
And I'll just call it in like:
$flickr = new Flickr($flickr_key, $flickr_secret);
$query = 'Kaspersky Internet Security 2013';
$tags = 'software';
$results = $flickr->searchPhotos($query, $tags);
foreach($results as $img){
$src = "http://farm" . $img['farm'] . ".static.flickr.com/" . $img['server'] . '/' . $img['id'] . '_' . $img['secret'] . '_m.jpg';
?>
<img src="<?php echo $src; ?>"/>
<?php
}
The problem here is that I'm getting duplicate images from time to time.
I also tried using the phpflickr library. But I'm still having the same issues:
$flickr = new phpFlickr($api_key);
$args = array(
'text' => 'Kaspersky Internet Security 2013',
'tags' => 'software',
'per_page' => '10',
'safe_search' => '1',
'content_type' => '4',
'media' => 'photos',
'sort' => 'relevance',
'privacy_filter' => '1'
);
$results = $flickr->photos_search($args);
$hashes = array();
$sources = array();
$images = $results['photo'];
foreach($images as $img){
$src = "http://farm" . $img['farm'] . ".static.flickr.com/" . $img['server'] . '/' . $img['id'] . '_' . $img['secret'] . '_m.jpg';
$current_hash = sha1_file($src);
if(!in_array($current_hash, $hashes)){
?>
<img src="<?php echo $src; ?>" alt="">
<?php
}
$hashes[] = $current_hash;
}
As you can see from the above code I've used sha1_file method to compare the hashes of each of the images returned from flickr. But that's a big performance hit:
without sha1_file: 0.81311082839966
with sha1_file: 6.8974900245667
Any ideas what else can I do to prevent flickr from returning duplicates? As you can see I'm only returning 10 images and that's all I need. I've also tried to add as many arguments that matches my needs but still no luck. Thanks in advance!
try on API explorer, will this give you the same result?
I tried using the param you specified, it returns 34 result in total..

json_decode deals with arrays and objects

Here's the function I created to grab Delicious recent bookmarks via cURL auth and then XML->JSON conversion:
<?php
// JSON URL which should be requested
$json_url = 'https://api.del.icio.us/v1/posts/recent';
$username = 'myusername'; // authentication
$password = 'mypassword'; // authentication
// Initializing curl
$ch = curl_init( $json_url );
// Configuring curl options
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERPWD => $username . ":" . $password // authentication
);
// Setting curl options
curl_setopt_array( $ch, $options );
$cache_delicious = '/BLAHBLAH/'.sha1($json_url).'.json';
if(file_exists($cache_delicious) && filemtime($cache_delicious) > time() - 1000){
// if a cache file newer than 1000 seconds exist, use it
$data_delicious = file_get_contents($cache_delicious);
} else {
$delicious_result = simplexml_load_string(curl_exec($ch));
$data_delicious = json_encode($delicious_result);
file_put_contents($cache_delicious, $data_delicious);
}
$obj = $data_delicious['post']['#attributes'];
foreach (array_slice(json_decode($data_delicious, true), 0, 5) as $obj) {
$delicious_title = str_replace('"', '\'', $obj['description']);
$delicious_url = htmlentities($obj['href'], ENT_QUOTES, "UTF-8");
$output = "<li><a rel=\"external nofollow\" title=\"$delicious_title\" href=\"$delicious_url\">$delicious_title</a></li>";
echo $output;
}
?>
Here's the JSON if I do a print_r($data_delicious);, reduced only to one entry for readability:
{
"#attributes":{
"tag":"",
"user":"myusername"
},
"post":[
{
"#attributes":{
"description":"Fastweb: fibra o VDSL? Disinformazione alla porta",
"extended":"",
"hash":"d00d03acd6e01e9c2e899184eab35273",
"href":"http:\/\/storify.com\/giovannibajo\/fastweb-fibra-o-vdsl",
"private":"no",
"shared":"yes",
"tag":"",
"time":"2013-06-14T10:30:08Z"
}
}
]
}
Unfortunately there's something wrong with the variables ($delicious_title and $delicious_url) in foreach, as I get Undefined index: description and href.
try to catch the error by using json-last-error
If you read the manual for json_decode you can see the second parameter. If you set it to true the output will be an array. So simply use array_slice(json_decode($data_delicious, true), 0, 5).
Better would be to get some error checking before hand.
<?php
$result = json_decode($data_delicious, true);
if (is_array($result)) {
foreach (array_slice($result, 0, 5) as $obj) {
$delicious_title = str_replace('"', '\'', $obj->description);
$delicious_url = htmlentities($obj->href, ENT_QUOTES, "UTF-8");
$output = "<li><a rel=\"external nofollow\" title=\"$delicious_title\" href=\"$delicious_url\">$delicious_title</a></li>";
echo $output;
}
}
?>
error clearly saying
your variable obj is undefined
try this
$obj_delicious = json_decode($data_delicious, true);
foreach (array_slice($obj_delicious, 0, 5) as $obj)
{ $delicious_title = str_replace('"', '\'', $obj['post']['#attributes']['description']);
$delicious_url = htmlentities($obj['post']['#attributes']['href'], ENT_QUOTES, "UTF-8");
$output = "<li><a rel=\"external nofollow\" title=\"$delicious_title\" href=\"$delicious_url\">$delicious_title</a></li>";
echo $output;
}
}

Categories