Hi my goal is to produce youtube thumbnail from a youtube link.
I have two files. in form.php, I enter the youtube link... The code there is simple and irrelevant, not writing here for not to congest the text of my question.
Anyway, form.php sends the youtube link text to the second file. (so 'a' below contains a youtube link that I enter in form.php and is coming from form.php.)
The code below is the code of second file. It strips the youtube link text and gives me a link for a thumbnail.
Here is the code of 2nd file.
$regexp = '/v=([a-z0-9]+)/i';
$url=$_POST['a'];
if (preg_match($regexp, $url, $matches)) {
$a = $matches[1];
}
else {
echo 'No match found';
}
$url2='http://img.youtube.com/vi/$id/default.jpg';
$result=str_replace ( '$id' , $a , $url2 );
echo $result;
this worked when I entered in the form:
http://www.youtube.com/watch?v=nnR8fDW3Ilo
and gave the result of:
http://img.youtube.com/vi/nnR8fDW3Ilo/default.jpg
(which works, and when I copy and paste this link into my browser, it produced the thumbnail i wanted)
but...
it didnt work (meaning, it didnt produce a link for the thumbnail) when I entered this link in my form:
http://www.youtube.com/watch?v=-KxjVlaLBmk&feature=youtu.be
and the code above gave me the result of
No match foundhttp://img.youtube.com/vi//default.jpg
How can I make the code work with this link as well, to produce me youtube thumbnail?