How to Embed Youtube Videos in PHP

How to embed YouTube videos in PHP?

You have to ask users to store the 11 character code from the youtube video.

For e.g. http://www.youtube.com/watch?v=Ahg6qcgoay4

The eleven character code is : Ahg6qcgoay4

You then take this code and place it in your database. Then wherever you want to place the youtube video in your page, load the character from the database and put the following code:-

e.g. for Ahg6qcgoay4 it will be :

<object width="425" height="350" data="http://www.youtube.com/v/Ahg6qcgoay4" type="application/x-shockwave-flash"><param name="src" value="http://www.youtube.com/v/Ahg6qcgoay4" /></object>

Find youtube Link in PHP string and Convert it into embed code?

Try this:

preg_replace("/\s*[a-zA-Z\/\/:\.]*youtube.com\/watch\?v=([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i","<iframe width=\"420\" height=\"315\" src=\"//www.youtube.com/embed/$1\" frameborder=\"0\" allowfullscreen></iframe>",$post_details['description']);

Youtube iframe video using php


<iframe width="560" height="315" src="https://www.youtube.com/embed/<?$row['ycode']?>" frameborder="0" allowfullscreen></iframe>

Change To

<iframe width="560" height="315" src="https://www.youtube.com/embed/<?php echo $row['ycode'];?>" frameborder="0" allowfullscreen></iframe>


Related Topics



Leave a reply



Submit