PDA

View Full Version : PHP and Yahoo Pipes


sam_h
09-25-2008, 02:15 AM
Hi all,

I have created a Y!Pipe for my site. I want to export the pipe as php and then display the content of the feed in my latest news section.

I am a beginner with PHP and am learning as I go, but I have managed to call the pipe and get it to display as follows: http://onyahead.com/news_php.php

obviously there is no styling whatsoever but I was quite happy to simply get the content displayed.

To call the pipe I used the following code:

<?php

error_reporting(E_ALL);

// output=php means that the request will return serialized PHP
$request = 'http://pipes.yahoo.com/pipes/pipe.run?_id=wO7isSpn3RGPcxwo_w6H4A&_render=php';

$response = file_get_contents($request);

if ($response === false) {
die('Request failed');
}

$phpobj = unserialize($response);

echo '<pre>';
print_r($phpobj);
echo '</pre>';

?>

I am looking for help to now get this code to display the title of each post as a link and a brief description (currently it is displaying the whole article), and obviously get it to look half decent and actually fit on my page!!

I am trying with this PHP malarky, but I could do with a shove in the right direction here!

Thanks in advance

Fou-Lu
09-25-2008, 03:16 AM
I'm not 100% certain how you want to handle you're data, and how these are run on you're site, but you've simply got a multi-dimensional array. You'll probably want something like this:

if (is_array($phpobj))
{
foreach ($phpobj['value']['items'] AS $key => $val)
{
printf("<div><p><a href=\"%s\">%s</a></p><p>%s</p>\n", $val['link'], $val['title'], $val['description']);
}
}

Or something of the sorts. I'm not at a computer I can test at, so I don't know for certainty that will work. Place anywhere after you're unserialize call.

sam_h
09-25-2008, 09:40 AM
i can't quite express how grateful I am for your help!

I have been trying to do this for a long while, and I ended up settling for a simple javascript output...not helping my SEO cause at all!

I basically replaced

echo '<pre>';
print_r($phpobj);
echo '</pre>';

with the lines of code you provided

thanks a lot!

Fou-Lu
09-26-2008, 12:55 AM
Great, I'm glad it worked on the first shot since I didn't have a means to test it this week :P
Cheers mate!