Joao Zanetti Joao Zanetti - 1 year ago 151
PHP Question

Iframe in PHP with string from SQL

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(
"<iframe src=\"//$2\" allowfullscreen></iframe>",

String that receive YouTube link from SQL


Answer Source

If you execute this, you will see the embeded youtube video. The $object is the embeded youtube url.

$url = "";
parse_str( parse_url( $url, PHP_URL_QUERY ), $v );
$object = '<iframe width="560" height="315" src="'.$v['v'].'" frameborder="0" allowfullscreen></iframe>';
echo $object;

Instead of the $url you can obviously just use your $row['link']

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download