Another scraper, this time for Youtube:
USAGE:
1 | <?php youtube("BMW") ?> |
CODE:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <?php function youtube($keyword) { $url = 'http://www.youtube.com/rss/tag/'.urlencode($keyword).'.rss'; $youtube = fopen($url, "r"); if (preg_match('/<enclosure url=\"(.*)swf/s', $youtube, $y)) { $youtube = $y[1]; $youtube = substr($y[1], 0, 36); $video = ''; $video .= "\n".'<object type="application/x-shockwave-flash" style="width:400px; height:325px;" data="'.$youtube.'">'; $video .= "\n".'<param name="movie" value="'.$youtube.'" />'; $video .= "\n".'</object>'; $video .= "\n"; print $video; } } ?> |
uhm.. doesn’t work for me..
I get a blank page..
Nils you are right, I was missing this line:
$youtube = fopen($url, “r”);
I just updated the code with the fix.
Thanks for the code…I am anxious to use it!
Is this code working correctly? I am getting a blank page and
am not sure if it is an error that I made or if the code still
needs more updating.
There is a very good chance that I messed up so forgive me if
it is my fault
Warning: preg_match() expects parameter 2 to be string, resource given in /home/public_html/004/youtube.php on line 5
I’m getting this error.
I don’t have any idea of how to use this script. Can you please give us some detailed instruction for doing it? I have messaged you on Digital point forum about this. Please guide me.
It’s actually really easy, just copy the code and save it on a file (youtube.php for example). Then wherever you want to insert a Youtube video related to a keyword, just add this:
require_once(‘youtube.php’); // assuming your file is called youtube.php
And then just wherever you want to see the video add this:
youtube(‘bmw’); // this will include a youtube video about BWM
Will this make my blog automated? Or should I have to add any cronjob or something to control the frequency of updating my blog?
No it wont post automatically but will give your site or page dynamic content.
Thanks for this. I’ve been wondering how to get something like this working for a while.
Wayne
Thanks for the script, that will come in handy on a new project that I am working on. =)
This code doesn’t work.Just gives me a blank page
if you guys are looking for good tools to get back links, i found some good ones at this website here
http://www.webthangs.com