Home  >  Article  >  Backend Development  >  How to Embed YouTube Videos on a PHP-Based Website?

How to Embed YouTube Videos on a PHP-Based Website?

Linda Hamilton
Linda HamiltonOriginal
2024-10-18 16:36:03738browse

How to Embed YouTube Videos on a PHP-Based Website?

Embedding YouTube Videos in PHP

Want to display YouTube videos on your PHP-based website? Here's how it's done:

Step 1: Obtain the Unique Video Code

Request users to provide the unique 11-character code found in the YouTube video URL. For instance, for the URL http://www.youtube.com/watch?v=Ahg6qcgoay4, the code is Ahg6qcgoay4.

Step 2: Store the Code in a Database

Record the obtained code in a database for future use.

Step 3: Embed the Video

Use the following HTML code to embed the video anywhere on your webpage:

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

Example

For the video with the code Ahg6qcgoay4, the embed code would be:

<code class="html"><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></code>

The above is the detailed content of How to Embed YouTube Videos on a PHP-Based Website?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn