0

i have implemented a function for grabbing Youtube ID and i use the regular expression:

preg_match('%(?:youtube(?:-nocookie)?\.com/(?:(?:v|e(?:mbed)?)/|.*[?&]v=|[^/]+/.+/)|youtu\.‌​be/)([^"&?/ ]{11})%i', $sourceCode, $youtube)) 

My problem is that this resular expression doesn't collect the id from a URL like: http://img.youtube.com/vi/Di9mQ35zprs/0.jpg

So, how can i change it to work as it works right now but by giving me the "Di9mQ35zprs" from a URL "http://img.youtube.com/vi/Di9mQ35zprs/0.jpg" too?

Thank you!

Nick
  • 201
  • 1
  • 5
  • 13
  • Could you add some value of $sourceCode to topic? – vural Jan 09 '15 at 10:06
  • It could be: $SourceCode = 'http://img.youtube.com/vi/Di9mQ35zprs/0.jpg'; – Nick Jan 09 '15 at 10:36
  • you can use preg_match('|\/vi\/([A-Z0-9]{11})\/|si', $sourceCode, $youtube); var_dump($youtube[1]); – vural Jan 09 '15 at 11:53
  • vural thank you for answering! Unfortunately your answer doesn't help because some times $SourceCode can have many other texts too. I want to keep my preg_match but with the difference to recognize the URL 'img.youtube.com/vi/Di9mQ35zprs/0.jpg' too and grab the ID. – Nick Jan 09 '15 at 19:13

0 Answers0