PHP Form to MySQL Embed - php

I have a form for updating my database. The form contains an embed-video-section which calls the embed code on a separate page to display the video in the page.
The problem is that embed links uses <iframes> which would be removed by my striptags.
I need some help in safely inserting the embed code from my form to my database.
The embed codes look like this
<iframe width="420" height="315" src="http://www.youtube.com/embed/Ahg6qcgoay4" frameborder="0" allowfullscreen></iframe>
or <iframe src="http://blip.tv/play/hIVVgfKwRgI.html" width="550" height="339" frameborder="0" allowfullscreen></iframe>

You could try to use BBCodes. For example, [embed param1=value param2=value] and so on..

Related

How to play youtube video from MySQL database

I have a form which a user can enter a youtube link along with their product. I want to be able to play that video (which it's link is stored in a MySQL database, the problem is that the <iframe> tag needs a youtube "Embed" link and not the URL, is there a way to convert the URL to the Embed link?
video_url = https://www.youtube.com/watch?v=1DIDWWKk8Bg
//code to connect to MySQL DB and get all rows
$videourl = $row["video_url"];
}
?>
<iframe width="420" height="345" src="<?php $videourl?>">
</iframe>
Regular YouTube link look like this
https://www.youtube.com/watch?v=1234
Embed YouTube link look like this
https://www.youtube.com/embed/1234
You need just to replace this watch?v= to embed/
$link = "https://www.youtube.com/watch?v=1234";
echo str_replace("watch?v=", "embed/",$link);
You have to use embed.
like this.
$videourl = explode("https://www.youtube.com/watch?v=", $row['videourl']);
<iframe class="iframeVideo" src="https://www.youtube.com/embed/' . $videourl[1] . '"></iframe>
$videourl has to look like this https://www.youtube.com/watch?v=3J6o7hcm8bE
I hope this works for you.
You cannot not use the exact url from the youtube video. The url used in iframes has the following format http://www.youtube.com/embed/unique_id_here. So you only have to save the unique_id for each video. It is only a part of the url. For example, from this url: https://www.youtube.com/watch?v=hdhjs88737&list=RDEMnLv8DM0l6F9uGd8jrENGgg&index=3, the unique id is the one in bold: hdhjs88737. So here is what I would do. Go to any video on youtube and click the share option, under the options select embed. Then copy the code. It will look like this:
<iframe width="560" height="315" src="https://www.youtube.com/embed/<unique_id_here>" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
Modify the parameters in the iframe to fit your preferences then only save the unique_id to your database. That should solve your problem. Check this API reference for a detailed guide.
Here is what I used, I'm not sure if this code should be there twice but it works so...
<?php
str_replace("watch?v=", "embed/",$videourl);
?>
<iframe width="520" height="345" src="<?php echo str_replace("watch?v=", "embed/",$videourl);?>">
</iframe>
Thank you for the help.

How to store original iframe markup into database without html encoding

I am new in PHP and I have wysihtml5 editor in my form and when I am adding iframe code in editor to store value into database iframe code encoded like:
<iframe width="560" height="315" src="<a target="_blank" rel="nofollow" href="http://www.youtube.com/embed/ycHXRWRKrdA?rel=0"">http://www.youtube.com/embed/ycHXRWRKrdA?rel=0"</a>; frameborder="0" allowfullscreen></iframe><br>
I want to store iframe code like below
<iframe width="560" height="315" src="http://www.youtube.com/embed/ycHXRWRKrdA?rel=0" frameborder="0" allowfullscreen></iframe>
Any idea?
you should apply http://php.net/manual/en/function.htmlspecialchars-decode.php to your string when is saved or when is displayed

How to play youtube video link in php

I want to play youtube video link on my php page
youtube link is
https://www.youtube.com/watch?v=VAJK04HOLd0
<object width="420" height="315" data="https://www.youtube.com/watch?v=VAJK04HOLd0">
i am try this code but it's not working
You can load the video file in <iframe>. Try this sample code,
<iframe width="560" height="315" src="https://www.youtube.com/embed/VAJK04HOLd0" frameborder="0" allowfullscreen></iframe>
Look at the last part of the url https://www.youtube.com/embed/VAJK04HOLd0,
VAJK04HOLd0
Which is the youtube video code. If you want to change the video change the code.
To embed YouTube videos, you should be using an iframe.
<iframe id="ytplayer" type="text/html" width="640" height="390" src="http://example.com/?autoplay=1" frameborder="0"/>
It's not connected to php.
You will want to include &autoplay=1 to the youtube string.

PHP: Using google map embed iframe and pulling a postcode from the database to display

http://www.youtube.com/watch?v=HTm-3Cduafw
Above is basically what I am after but I have tried everything to get it working...I want to pull the postcode from the database and use that, instead of a full address. Its so each user has a different map position, based on what postcode is stored in their account, in the database.
Im using dreamweaver, I have brought in the recordset and the php bit that I am trying to use is below.
<?php echo "$postcode";?>
Above is the snippet and below is what i have so far
<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.co.uk/maps?f=q&source=s_q&hl=en&geocode=&q=<?php echo "$postcode";?>&aq=&t=h&g=<?php echo "$postcode";?>&ie=UTF8&hq=&hnear=<?php echo "$postcode";?>&z=13&output=embed"></iframe>
Thanks guys!
Just use & instead of &, because $amp; is the html tag

How to get around This Content cannot be displayed in a frame? (Youtube issue)

I'm trying to keep a database of posted videos on a site I am currently developing. To be able to do this I have to store the URLs of the videos into a database and then I call the url from the database using php and sql by doing this bare in mind I am using this from a php defined area on my homepage. If I use this code it works on other video post sites!
echo '<iframe width="640" height="390" src="', $row['Post_URL'],'"frameborder="0" allowFullScreen></iframe>';
This will not work it says content cannot be displayed in a frame but if I do this it works.
<?php
echo '<iframe width="560" height="315" src="http://www.youtube.com/embed/wardQ7W8hPU" frameborder="0" allowfullscreen></iframe>';
?>
why does the one work properly and the other not? what is a way around this so I can call from the database into php and echo it out so it will display properly on the page?
I got the same problem today. As stated in one of the comments, the problem is the url used...
The iframe embed only works with urls looking like:
http://www.youtube.com/embed/[video_id]
Most of people are using the "share" feature, that generates minified urls like:
http://youtu.be/[video_id]
However, if you look into the "embed" feature, you'll notice that it generates an iframe with src urls like the first example.
So to answer the question, when using iframes to embed, use the src url like the first example.
Try this
<iframe width="640" height="390" src="<?php echo $row['Post_URL'] ?>" frameborder="0" allowFullScreen></iframe>
OR this
<?php
echo "<iframe width='640' height='390' src='{$row['Post_URL']}' frameborder='0' allowFullScreen></iframe>";
?>
OR this
<?php
echo "<iframe width='640' height='390' src='" . $row['Post_URL'] . "' frameborder='0' allowFullScreen></iframe>";
?>
they all are the same and will do the same process.
I'm doing this with dynamic data and it's easier for the client to use the youtube Share link.
So... it's then just a matter of getting the youtube video ID from that url.
// we can't use the "share" link so need to just get the video ID
$youtubePath = parse_url($youtubeShareLink,PHP_URL_PATH);
$youtubeId = str_replace('/','',$youtubePath);
and now we can use the ID in an iframe (adjust width and height per embed options in youtube)
<iframe width="560" height="315" src="//www.youtube.com/embed/<? echo $youtubeId; ?>?rel=0" frameborder="0" allowfullscreen></iframe>

Categories