Lukeidiot Posted August 27, 2009 Share Posted August 27, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/172088-php-youtube-username-grabber/ Share on other sites More sharing options...
ignace Posted August 27, 2009 Share Posted August 27, 2009 http://code.google.com/intl/nl/apis/youtube/overview.html Quote Link to comment https://forums.phpfreaks.com/topic/172088-php-youtube-username-grabber/#findComment-907342 Share on other sites More sharing options...
Lukeidiot Posted August 29, 2009 Author Share Posted August 29, 2009 http://code.google.com/intl/nl/apis/youtube/overview.html This did not really help, but thanks for posting. Quote Link to comment https://forums.phpfreaks.com/topic/172088-php-youtube-username-grabber/#findComment-908822 Share on other sites More sharing options...
Prismatic Posted August 29, 2009 Share Posted August 29, 2009 <?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 ) Quote Link to comment https://forums.phpfreaks.com/topic/172088-php-youtube-username-grabber/#findComment-908826 Share on other sites More sharing options...
dreamwest Posted August 29, 2009 Share Posted August 29, 2009 <?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?? Quote Link to comment https://forums.phpfreaks.com/topic/172088-php-youtube-username-grabber/#findComment-908832 Share on other sites More sharing options...
trq Posted August 29, 2009 Share Posted August 29, 2009 file_get_contents would be preferred over curl if its a simple page request. Quote Link to comment https://forums.phpfreaks.com/topic/172088-php-youtube-username-grabber/#findComment-908835 Share on other sites More sharing options...
Lukeidiot Posted August 29, 2009 Author Share Posted August 29, 2009 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/172088-php-youtube-username-grabber/#findComment-908858 Share on other sites More sharing options...
Prismatic Posted August 29, 2009 Share Posted August 29, 2009 Simple. echo implode(", ", $matches[1]); Quote Link to comment https://forums.phpfreaks.com/topic/172088-php-youtube-username-grabber/#findComment-908860 Share on other sites More sharing options...
Lukeidiot Posted August 29, 2009 Author Share Posted August 29, 2009 Simple. echo implode(", ", $matches[1]); Thank you so much, this is exactly what I needed. Quote Link to comment https://forums.phpfreaks.com/topic/172088-php-youtube-username-grabber/#findComment-908861 Share on other sites More sharing options...
Prismatic Posted August 29, 2009 Share Posted August 29, 2009 Welcome Quote Link to comment https://forums.phpfreaks.com/topic/172088-php-youtube-username-grabber/#findComment-908862 Share on other sites More sharing options...
dreamwest Posted August 29, 2009 Share Posted August 29, 2009 <?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 } Quote Link to comment https://forums.phpfreaks.com/topic/172088-php-youtube-username-grabber/#findComment-908868 Share on other sites More sharing options...
Prismatic Posted August 29, 2009 Share Posted August 29, 2009 <?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, Quote Link to comment https://forums.phpfreaks.com/topic/172088-php-youtube-username-grabber/#findComment-908869 Share on other sites More sharing options...
dreamwest Posted August 29, 2009 Share Posted August 29, 2009 Your right Quote Link to comment https://forums.phpfreaks.com/topic/172088-php-youtube-username-grabber/#findComment-908870 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.