I'm trying to convert a YouTube video link to You Tube embed link. A string will receive the YouTube link from SQL, another code will convert to embed link and converted link will be used inside a iframe. I don't know why its not working.
YouTube converter code (I'm trying to use any of these: Link to Embed)
function convertYoutube($string) {
return preg_replace(
"/\s*[a-zA-Z\/\/:\.]*youtu(be.com\/watch\?v=|.be\/)([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i",
"<iframe src=\"//www.youtube.com/embed/$2\" allowfullscreen></iframe>",
$string
);
}
String that receive YouTube link from SQL
$row["link"]