What I have is a youtube link: http://www.youtube.com/watch?v=xxxxxxxxxxx I can detect http://www.youtube.com/watch?v= in a string, but how do I get the following 11 characters into a variable? gracious! adbox
$link = 'http://www.youtube.com/watch?v=16afe495'; preg_match('%\?v=([^&]+)%', $link, $matches); echo $matches[1]; PHP: Totally untested but that should do it
try this $page_source = '<retrived via CURL/fopen contain the HTML code of the website page>'; $flag = 'http://www.youtube.com/watch?v='; $pos_start = strpos($page_source, $flag) + strlen($flag); //The next 11 characters $video_id = substr($page_source, $pos_start, 11); PHP: Hope it works well!
Could also use $link = 'http://www.youtube.com/watch?v=16asdfsdfsdfsdffe495'; preg_match('%watch\?v=(.{11})%', $link, $matches); echo $matches[1]; PHP: I'm guessing that my code matched more than 11 characters?
Well, if you are just after a single link, you should use my method. If you after multiple video links, you should regex as given by jay.