Jump to content

PHP youtube Username Grabber


Lukeidiot

Recommended Posts

I am trying to make an application that grabs the youtube usernames from a given link.

 

Here is an example:

 

I would like to pull the usernames from this url: http://www.youtube.com/browse?s=bzb

 

and display them like such:

Joe1, hello3, test3, hellotest44

 

Is this easy to do? If so could anyone care to assist me with this? :)

 

Thanks in advance.

 

EDIT: Here is an example of kinda what I'd like, but just grabbing different data

http://answers.google.com/answers/threadview/id/36615.html

Link to comment
https://forums.phpfreaks.com/topic/172088-php-youtube-username-grabber/
Share on other sites

<?php
$page = "http://www.youtube.com/browse?s=bzb";
$page_contents = file_get_contents($page);

$names = preg_match_all('/<span class="video-username"><a id="video-from-username-.*" class="hLink"  href="\/user\/(.*)">.*<\/a><\/span>/', $page_contents, $matches);
print_r($matches[1]);

?>

 

Output

Array
(
    [0] => ifbnews
    [1] => sigves
    [2] => lunamaria0708
    [3] => PrismWeapon
    [4] => sugoidrama070109
    [5] => ebonite45
    [6] => AluminumFoils
    [7] => VenetianPrincess
    [8] => NGRNinfa
    [9] => cheezburger
    [10] => MootPoon817
    [11] => SouljaBoy
    [12] => NationalGeographic
    [13] => jobros1love1dream2
    [14] => cplfreeman
    [15] => 10LMessi7CRonaldo
    [16] => betamaxdc
    [17] => failblog
    [18] => DjGhostM
    [19] => jameslikecoulter
    [20] => XxNewXDisneyxX
    [21] => MondoMedia
    [22] => NokiaConversations
)

<?php
$page = "http://www.youtube.com/browse?s=bzb";
$page_contents = file_get_contents($page);

$names = preg_match_all('/<span class="video-username"><a id="video-from-username-.*" class="hLink"  href="\/user\/(.*)">.*<\/a><\/span>/', $page_contents, $matches);
print_r($matches[1]);

?>

 

Output

Array
(
    [0] => ifbnews
    [1] => sigves
    [2] => lunamaria0708
    [3] => PrismWeapon
    [4] => sugoidrama070109
    [5] => ebonite45
    [6] => AluminumFoils
    [7] => VenetianPrincess
    [8] => NGRNinfa
    [9] => cheezburger
    [10] => MootPoon817
    [11] => SouljaBoy
    [12] => NationalGeographic
    [13] => jobros1love1dream2
    [14] => cplfreeman
    [15] => 10LMessi7CRonaldo
    [16] => betamaxdc
    [17] => failblog
    [18] => DjGhostM
    [19] => jameslikecoulter
    [20] => XxNewXDisneyxX
    [21] => MondoMedia
    [22] => NokiaConversations
)

 

Is this quicker than CURL or the same speed/resources??

<?php
$page = "http://www.youtube.com/browse?s=bzb";
$page_contents = file_get_contents($page);

$names = preg_match_all('/<span class="video-username"><a id="video-from-username-.*" class="hLink"  href="\/user\/(.*)">.*<\/a><\/span>/', $page_contents, $matches);
print_r($matches[1]);

?>

Thank you so much, this is exactly what I was looking for!

 

How would I list them without the array information? For example, make it say this:

user1, user2, user3

<?php
$page = "http://www.youtube.com/browse?s=bzb";
$page_contents = file_get_contents($page);

$names = preg_match_all('/<span class="video-username"><a id="video-from-username-.*" class="hLink"  href="\/user\/(.*)">.*<\/a><\/span>/', $page_contents, $matches);
print_r($matches[1]);

?>

Thank you so much, this is exactly what I was looking for!

 

How would I list them without the array information? For example, make it say this:

user1, user2, user3

 

 

 

 

This is more flexible:

 

foreach ($matches[1] as $value) {
echo   $value; // add anything you want in front of or after 
}

<?php
$page = "http://www.youtube.com/browse?s=bzb";
$page_contents = file_get_contents($page);

$names = preg_match_all('/<span class="video-username"><a id="video-from-username-.*" class="hLink"  href="\/user\/(.*)">.*<\/a><\/span>/', $page_contents, $matches);
print_r($matches[1]);

?>

Thank you so much, this is exactly what I was looking for!

 

How would I list them without the array information? For example, make it say this:

user1, user2, user3

 

 

 

 

This is more flexible:

 

foreach ($matches[1] as $value) {
echo   $value; // add anything you want in front of or after 
}

 

Sure if you want your result to be.

 

, name, name, name, name, 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.