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
Resize Iframe Height According to Content Height in It
How to Hide/Encode/Encrypt PHP Source Code and Let Others Have the System
Why Use a Psr-0 or Psr-4 Autoload in Composer If Classmap Is Actually Faster
How to Get Response Using Curl in PHP
Check Whether Image Exists on Remote Url
How to Check If the Current Date/Time Is Past a Set Date/Time
Symfony2 Conceptual Issue: General Bundles Vs. Specific Ones
How to Embed Youtube Videos in PHP
PHP How to Get Local Ip of System
Sending Multiple Iphone Push Notifications + Apns + PHP
Calculate Age Based on Date of Birth
PHP: Check If an Array Contains All Array Values from Another Array
PHP Setcookie "Samesite=Strict"
Best Way to Completely Destroy a Session - Even If the Browser Is Not Closed
Warning: Domdocument::Loadhtml(): Htmlparseentityref: Expecting ';' in Entity,