rc69, on Jul 16 2009, 11:08 PM, said:
Ok, i just tested your code and it worked fine for me (not even a warning). What version of PHP are you using?
Also, it looks like you trimmed down the code a bit to keep things simple, could you post the whole containing block and include a comment next to the line which is generating the error (i.e. what ever if-statment/while loop this code is running in)?
PHP 5.2.9-2
I've made a few changes, no more errors, but I can't extract data from the simplexml object. My original plan was to put everything into a data array, but I tried a slightly different approach that still isn't working.
If you could find a way to get all the data I want into an array that I can access in test2.php you would be a hero.
test2.php
<?php
//test 2
require("video.php");
$grabbr = new grabbr();
$grabbr->get_youtube("http://www.youtube.com/watch?v=fiAb1HuiHyA&eurl=http%3A%2F%2Fwww.youtube.com%2Fuser%2Fdeedlebag&feature=player_profilepage");
echo "<pre>";
echo $grabbr->get_title();
?>
video.php
<?php
class grabbr
{
// this is all the data
public $id = null;
public $title = null;
public $postdate = null;
public $description = null;
/////////////////////////////////
//Youtube Function
function get_youtube($url)
{
//parse youtube url into the id
if (preg_match('%youtube\\.com/(.+)%', $url, $id)) {
$id = $id[1];
$replace = array("watch?v=", "v/", "vi/");
$id = substr(str_replace($replace, "", $id), 0, 11);
} else {
return "Error with url.";
}
//get video object
$file = "http://gdata.youtube.com/feeds/api/videos/".$id;
$obj_video = simplexml_load_file($file);
echo "<pre>";
print_r($obj_video);
//this is where it's going wrong
$title = $obj_video->title;
////////////////////////////////////////
}
}
?>