Bleucube Posted March 3, 2014 Share Posted March 3, 2014 Howdy. First time poster, newbie coder. I've scanned the forums for the last couple hours and although there are some close answers - nothing works nor accomplishes my job. My goal: Scrape a website, find all youtube links, create a page with all videos found via iframe. My Issue:My code below works great, but all the URLS look like http://www.youtube.com/watch?v=xxxxxxxxxxx Not sure what to do. Should I use str_replace to change it from that to http://www.youtube.com/embed/xxxxxxxx ? Here's the code: <?php $curl = curl_init(); curl_setopt ($curl, CURLOPT_URL, "http://xxxxx"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec ($curl); curl_close ($curl); //links if(preg_match_all("/(http\:\/\/www\.youtube\.com\/watch\?v=\w{11})/", $result, $links)) { foreach($links[0] as $link) { echo $link."<br />"; } } ?> Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/286682-curl-preg_match_all-string-replace/ Share on other sites More sharing options...
Solution Ch0cu3r Posted March 3, 2014 Solution Share Posted March 3, 2014 (edited) No, just alter the regex to only capture the value of v= not the whole of the youtube url if(preg_match_all("/http\:\/\/www\.youtube\.com\/watch\?v=(\w{11})/", $result, $links)) { foreach($links[1] as $link) { echo "http://youtube.com/embed/$link<br />"; } } Edited March 3, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/286682-curl-preg_match_all-string-replace/#findComment-1471362 Share on other sites More sharing options...
Bleucube Posted March 3, 2014 Author Share Posted March 3, 2014 Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/286682-curl-preg_match_all-string-replace/#findComment-1471368 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.