How to embed YouTube videos in PHP?

Satish Ravipati picture Satish Ravipati · Jan 5, 2009 · Viewed 200.9k times · Source

Can anyone give me an idea how can we show or embed a YouTube video if we just have the URL or the Embed code?

Answer

Alec Smart picture Alec Smart · Jan 5, 2009

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>