PDA

View Full Version : [HELP] Getting info off an external page and putting it onto my own.



lolwut
15-07-2007, 01:14 PM
Hiii,

I am looking for help with trying to get hold of a bit of source code on a web page. For examples sake, let's say it's YouTube, and I want to get the video description.

For example. Let's say the URL is http://youtube.com/watch?v=p0DWvta7pg0
and I want to get this code off the page and onto mine:



<span id="vidDescBegin">
This is like the video description.
</span>
I want to do this as my site has a few of my favourite YouTube videos on it and I would like for the video descriptions to come up below the videos.

I'm not sure if you'd do


<?php
file_get_contents("http://youtube.com/watch?v=p0DWvta7pg0",<span id="vidDescBegin>,</span>");
?>
or something like that, any help appreciated greatly. will rep if i can.

Moved by opensourcehost (Forum Moderator) from Web Designing: Please post in the correct forum next time, thanks http://habboxforum.com/images/smilies/smile.gif.

timROGERS
15-07-2007, 06:28 PM
The easiest way is to use a little function that it easily available on the Internet called "get_string_between". Here is how you'd do it:



<?php
/* String function */
function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
/* End string function */

$yt = file_get_contents("URL OF YOUTUBE PAGE");
$spancontents = get_string_between($yt, "<span id='whatever-it-is'>", "</span>");
?>

Tomm
15-07-2007, 06:51 PM
Easier code :P



$tehsource = file_get_contents("www.youtube.com etc");
$step1 = explode('<span id="vidDescBegin">', $tehsource);
$step2 = explode('</span>', $step1[1]);
$youtubedescription = $step2[0];
:)

Mentor
16-07-2007, 12:28 PM
Genral purpous gabbing code i wrote a while back



//Genral Purpos content Grabbing Function.
//By Carl (http://thybag.co.uk)
function GrabContent($url,$prefix,$suffix){
// get page contents
$page = file_get_contents($url);
//search for matches
preg_match_all("#".$prefix."(.+?)".$suffix."#is", $page, $finds);
// [0] matches + param - [1] matches
return $finds[1];
}
//test it on habbox

$foundarray = GrabContent("http://www.habbox.com/site/","<div class='section' ><div class='shadow' ><div class='menuBox' >",'</div></div></div>');

print_r ($foundarray);


It returns a multi level array of everything maching the search paramiters, so if theres a repeteing part u can grab each one of them seperatly :)

kyle♥
17-07-2007, 04:22 PM
<object width="425" height="350"><param name="movie" value="<A href="http://www.youtube.com/v/p0DWvta7pg0"></param><param">http://www.youtube.com/v/p0DWvta7pg0"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/p0DWvta7pg0" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>

If it's just basic html, but I see your wanting PHP.

Tomm
17-07-2007, 04:47 PM
Err no. He does not want to play the video on his site.


<object width="425" height="350"><param name="movie" value="<A href="http://www.youtube.com/v/p0DWvta7pg0"></param><param">http://www.youtube.com/v/p0DWvta7pg0"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/p0DWvta7pg0" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>

If it's just basic html, but I see your wanting PHP.

Want to hide these adverts? Register an account for free!