i made a video.php page that will show the videos from youtube depending on id of the video on youtube,so i made something like that
if($_GET['id']=="jquery11"){
?>
<div id="video" ><iframe width="640" height="360" src="http://www.youtube.com/embed/6PM6t5RFR2w?autoplay=1&controls=2" frameborder="5" allowfullscreen></iframe></div>
<?
}
if($_GET['id']=="jquery12"){
?>
<div id="video" ><iframe width="640" height="360" src="http://www.youtube.com/embed/fE0GC7KFIno?autoplay=1&controls=2" frameborder="5" allowfullscreen></iframe></div>
<?
}
if($_GET['id']=="jquery13"){
?>
<div id="video" ><iframe width="640" height="360" src="http://www.youtube.com/embed/xuFa2R4c6Gc?autoplay=1&controls=2" frameborder="5" allowfullscreen></iframe></div>
<?
}
if($_GET['id']=="jquery14"){
?>
<div id="video" ><iframe width="640" height="360" src="http://www.youtube.com/embed/M971xYWiS7M?autoplay=1&controls=2" frameborder="5" allowfullscreen></iframe></div>
<?
}
if($_GET['id']=="jquery15"){
?>
<div id="video" ><iframe width="640" height="360" src="http://www.youtube.com/embed/oZ_J422z4WI?autoplay=1&controls=2" frameborder="5" allowfullscreen></iframe></div>
<?
}
if($_GET['id']=="jquery16"){
?>
<div id="video" ><iframe width="640" height="360" src="http://www.youtube.com/embed/tYJMitUfSvs?autoplay=1&controls=2" frameborder="5" allowfullscreen></iframe></div>
<?
}
if($_GET['id']=="jquery17"){
?>
<div id="video" ><iframe width="640" height="360" src="http://www.youtube.com/embed/wZPhQzqGzls?autoplay=1&controls=2" frameborder="5" allowfullscreen></iframe></div>
<?
}
if($_GET['id']=="jquery18"){
?>
<div id="video" ><iframe width="640" height="360" src="http://www.youtube.com/embed/Cdwn2JoCYQ0?autoplay=1&controls=2" frameborder="5" allowfullscreen></iframe></div>
<?
}
if($_GET['id']=="jquery19"){
?>
<div id="video" ><iframe width="640" height="360" src="http://www.youtube.com/embed/cKCiNf23Atg?autoplay=1&controls=2" frameborder="5" allowfullscreen></iframe></div>
<?
}
?>
any idea to change this method that will decrease get requests?i tried making associative array ,but i think it's same
$map = array(
"jquery11" => "6PM6t5RFR2w",
"jquery12" => "fE0GC7KFIno",
"jquery13" => "xuFa2R4c6Gc",
"jquery14" => "M971xYWiS7M",
"jquery15" => "oZ_J422z4WI",
"jquery16" => "tYJMitUfSvs",
"jquery17" => "wZPhQzqGzls",
"jquery18" => "Cdwn2JoCYQ0",
"jquery19" => "cKCiNf23Atg"
);
$id = $_GET['id'];
if( array_key_exists( $id, $map ) ) {
echo <<<HTML
<div id="video" >
<iframe width="640" height="360" src="http://www.youtube.com/embed/{$map[$id]}?autoplay=1&controls=2" frameborder="5" allowfullscreen>
</iframe>
</div>
HTML;
}
Create an array of your possible ids, and then check if the variable being passed is in the array by using in_array under an if statement, and then just assign the proper url from there.
Untested - should work tho:
<?php
$request = $_GET['request'];
$accepted_requests = array(1 =>'jquery1', 2 => 'jqery2', 3 => 'jquery3');
$utube_urls = array(1 => 'url', 2 => 'url', 3 => 'url');
if(in_array($request, $accepted_requests)){
foreach($accepted_requests as $k=>$v){
if($request === $v){
foreach($utube_urls as $keys => $vals){
if($k == $keys){
echo $vals;
}
}
}
}
}
?>
UPDATED THE CODE: Missed the 's' on $val - fixed now
Related
I have setup a video website but i need help to make $target_file change to the file url but it won't because it is in '' brackets and also at $stringdata
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
$myFile = "/home/darlpsou/video.darlingserver.com/$target_file.html"; // or .php
$fh = fopen($myFile, 'w'); // or die("error");
$stringData = '<h1>Title</h1>
<p> </p>
<p><video tabindex="0" poster="thumb.png" autoplay="autoplay" loop="loop" controls="controls" width="842" height="417">
<source src="http://video.darlingserver.com/$target_file" type="video/mp4" />
<iframe title="YouTube video player" width="842" height="417" src="http://www.youtube.com/embed/iYuG55vOIVc" frameborder="0" allowfullscreen="allowfullscreen">
</iframe></video></p>';
fwrite($fh, $stringData);
fclose($fh);
There are various ways to do this. One would be to use sprintf:
$stringData = sprintf('<h1>Title</h1>
<p> </p>
<p><video tabindex="0" poster="thumb.png" autoplay="autoplay" loop="loop" controls="controls" width="842" height="417">
<source src="http://video.darlingserver.com/%s" type="video/mp4" />
<iframe title="YouTube video player" width="842" height="417" src="http://www.youtube.com/embed/iYuG55vOIVc" frameborder="0" allowfullscreen="allowfullscreen">
</iframe></video></p>',
urlencode($target_file)
);
Another would be to use HEREDOC syntax:
$stringData = <<< HTML
<h1>Title</h1>
<p> </p>
<p><video tabindex="0" poster="thumb.png" autoplay="autoplay" loop="loop" controls="controls" width="842" height="417">
<source src="http://video.darlingserver.com/$target_file" type="video/mp4" />
<iframe title="YouTube video player" width="842" height="417" src="http://www.youtube.com/embed/iYuG55vOIVc" frameborder="0" allowfullscreen="allowfullscreen">
</iframe></video></p>
HTML;
Yet another would be to concatenate the variable:
$stringData = '<h1>Title</h1>
<p> </p>
<p><video tabindex="0" poster="thumb.png" autoplay="autoplay" loop="loop" controls="controls" width="842" height="417">
<source src="http://video.darlingserver.com/' . urlencode($target_file) .'" type="video/mp4" />
<iframe title="YouTube video player" width="842" height="417" src="http://www.youtube.com/embed/iYuG55vOIVc" frameborder="0" allowfullscreen="allowfullscreen">
</iframe></video></p>';
This is really strings 101 so please refer to http://php.net/strings for additional clues.
How can I detect and replace a soundcloud url in a text with an iframe using PHP:
For example:
This:
https://soundcloud.com/s/eminem-ft-dr-dre-old-time-sake
Into this:
<iframe width="100%" height="166" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/140068709&color=00aabb&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false"></iframe>
function linkifySoundcloudURLs( $text )
{
$text = preg_replace('#https{0,1}:\/\/w{0,3}\.*soundcloud\.com\/([^< ]+)#ix',
'<iframe width="100%" height="166" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https://soundcloud.com/$1&color=00aabb&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false"></iframe>',
$text);
return $text;
}
Works for me.
I'm not sure I understand you correctly, but something like this?
<?php
$url = "https://soundcloud.com/aathmigan/eminem-ft-dr-dre-old-time-sake";
?>
<iframe width="100%" height="166" scrolling="no" frameborder="no"
src="<?php echo $url; ?>"></iframe>
I am trying to access an item from the array, the issue is with the line:
src=$videoArray[0]
I have tried a few ways but none seem to work.
<?php
$videoArray = array(
"//www.youtube.com/embed/nEBHkEeH42Y",
"//www.youtube.com/embed/1GlticqrECU",
"//www.youtube.com/embed/BMOUsI8JIaI",
);
?>
<iframe width="520" height="280" src=$videoArray[0] frameborder="0" allowfullscreen></iframe>
You need <?php ?> tags for the array to echo out, and you are missing the quotes around the src attribute.
<iframe width="520" height="280" src="<?php echo $videoArray[0]; ?>" frameborder="0" allowfullscreen></iframe>
You forgot your PHP tags and echo statement:
<iframe width="520" height="280" src="<?php echo $videoArray[0]; ?>" frameborder="0" allowfullscreen></iframe>
or shorthand syntax:
<iframe width="520" height="280" src="<?= $videoArray[0]; ?>" frameborder="0" allowfullscreen></iframe>
<iframe width="520" height="280" src="<?php $videoArray[0] ?>" frameborder="0" allowfullscreen></iframe>
Maybe need reusable code...
<?php
$videoArray = array(
"//www.youtube.com/embed/nEBHkEeH42Y",
"//www.youtube.com/embed/1GlticqrECU",
"//www.youtube.com/embed/BMOUsI8JIaI",
);
foreach($videoArray as $videoLink) {
?>
<iframe width="520" height="280" src="<?php echo $videoLink; ?>" frameborder="0" allowfullscreen></iframe>
<?php
}
?>
I am currently looking at a piece of code for a friend and I am trying to strip out a piece of unwanted code but not sure how I can achieve what I want.
CODE:
<?php
$blah = '<iframe src="//player.vimeo.com/video/82444237" width="500" height="281"
frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
<p>KING OF THE BEASTS from
John Wiley on
Vimeo.</p>';
echo($blah);
?>
In this code the website is showing: from on
I want the start point of the input to be iframe and the endpoint to be /iframe.
Without manually making sure the iframe only is selected, any suggestions on how to achieve this?
Try this:
function blah($postTag)
{
//TERMINATES THE STRING AT </IFRAME>
$exploder = explode("iframe",$postTag);
//CALLS THE STRING UNTIL THE FIRST IFRAME INPUT AND CLOSES THE IFRAME TAG
$cleaned = "<iframe".$exploder[1]."iframe>";
return $cleaned;
}
$blahblah = blah('<iframe src="//player.vimeo.com/video/82444237" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> <p>KING OF THE BEASTS from John Wiley on Vimeo.</p>');
That should do it.
A simple strstr() will do the job.
<?php
$blah = '<iframe src="//player.vimeo.com/video/82444237" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> <p>KING OF THE BEASTS from John Wiley on Vimeo.</p>';
echo strstr($blah,'</iframe>',true)."</iframe>";
OUTPUT
<iframe src="//player.vimeo.com/video/82444237" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
$blah = '<iframe src="//player.vimeo.com/video/82444237" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> <p>KING OF THE BEASTS from John Wiley on Vimeo.</p>';
echo substr($blah, 0, strpos($blah, '</iframe>')) ."</iframe>";
Output:
<iframe src="//player.vimeo.com/video/82444237" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
Hopefully this'll be pretty simple for someone to help with, but my PHP is very limited so here goes:
I have a random array set up to pull in a different video on each page refresh, and I've set up a 'Next' link which, if pressed, refreshes the array and outputs the 'next' video. Thing is, it's not the 'next' video in the array as it's being passed through the random function and just outputting whichever is finds. In most cases, since there's only four videos in the array, it's the same video.
Each time the page is visited it needs to be a random video, but if 'Next' is pressed, it needs to continue in the array in a loop.
Here's my code so far:
<div class="video-container">
<?php
$randomNumber = rand(0,4);
$videoArray = array(
'<iframe src="http://player.vimeo.com/video/46808655?title=0&portrait=0&byline=0&color=ffffff" width="650" height="366" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>',
'<iframe src="http://player.vimeo.com/video/46803192?title=0&portrait=0&byline=0&color=ffffff" width="650" height="366" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>',
'<iframe src="http://player.vimeo.com/video/46811051?title=0&portrait=0&byline=0&color=ffffff" width="650" height="366" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>',
'<iframe src="http://player.vimeo.com/video/46817110?title=0&portrait=0&byline=0&color=ffffff" width="650" height="366" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>',
'<iframe src="http://player.vimeo.com/video/46822673?title=0&portrait=0&byline=0&color=ffffff" width="650" height="366" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>',
);
echo $videoArray[$randomNumber];
$current_index = array_search($randomNumber, $videoArray);
$next = $current_index - +1;
?>
</div>
<?php if ($videoArray > 0): ?>
Next
<?php endif; ?>
Any help would be mostly appreciated :)
How about something like this:
<div class="video-container">
<?php
if (isset($_REQUEST["video"])) {
$randomNumber = $_REQUEST["video"];
} else {
$randomNumber = rand(0,4);
}
$videoArray = array(
'<iframe src="http://player.vimeo.com/video/46808655?title=0&portrait=0&byline=0&color=ffffff" width="650" height="366" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>',
'<iframe src="http://player.vimeo.com/video/46803192?title=0&portrait=0&byline=0&color=ffffff" width="650" height="366" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>',
'<iframe src="http://player.vimeo.com/video/46811051?title=0&portrait=0&byline=0&color=ffffff" width="650" height="366" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>',
'<iframe src="http://player.vimeo.com/video/46817110?title=0&portrait=0&byline=0&color=ffffff" width="650" height="366" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>',
'<iframe src="http://player.vimeo.com/video/46822673?title=0&portrait=0&byline=0&color=ffffff" width="650" height="366" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>',
);
echo $videoArray[$randomNumber];
$current_index = array_search($randomNumber, $videoArray);
$next = $current_index - +1;
?>
</div>
<?php if ($videoArray > 0): ?>
Next
<?php endif; ?>
If the script is called with a parameter called video, it'll choose that as the 'random' number.
There are a couple of other tweaks that could to with adding, such as making sure that the chosen video exists, as well as thinking about what to do if someone hits Next when they're on the final video.
First, you should store only urls in your array.
Second, you should pass the id for the next video as url parameter in the Next link.
<div class="video-container">
<?php
// Array with video urls
$videoArray = array(
'http://player.vimeo.com/video/46808655?title=0&portrait=0&byline=0&color=ffffff',
'http://player.vimeo.com/video/46803192?title=0&portrait=0&byline=0&color=ffffff',
'http://player.vimeo.com/video/46811051?title=0&portrait=0&byline=0&color=ffffff',
'http://player.vimeo.com/video/46817110?title=0&portrait=0&byline=0&color=ffffff',
'http://player.vimeo.com/video/46822673?title=0&portrait=0&byline=0&color=ffffff'
);
// Verify if "videoid" has been passed and it is valid
if (isset($_GET["videoid"])
&& is_numeric($_GET["videoid"])
&& ($_GET["videoid"] >= 0)
&& ($_GET["videoid"] < count($videoArray))
{
// videoid is valid, use it
$videoid = $_GET["videoid"];
}
else
{
// videoid is invalid or not set, generate random videoid
$videoid = rand(0, count($videoArray) - 1);
}
?>
<iframe src="<?php print($videoArray[$videoid]); ?>" width="650" height="366" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen>
</iframe>
<?php
// calculate id for next video with overflow
$nextid = $videoid + 1;
if ($nextid >= count($videoArray))
$nextid = 0;
?>
</div>
Next
You have to set a $_GET parameter
Next
and randomNumber:
<?php
$videoArray = array(/* */);
if(isset($_GET['v']) && (int)$_GET['v'] < count($videoArray)){
$randomNumber = (int)$_GET['v'];
} else {
$randomNumber = rand(0,4);
}
$current_index = $videoArray[$randomNumber];
$next = $current_index+1;
if($next >= count($videoArray)){ $next = 0; }
........
Before any output of your script, type:
session_start();
Then do
if(!isset($_SESSION['curVid'])) {
$_SESSION['curVid'] = 0;
$_SESSION['videos'] = $videoArray;
shuffle($_SESSION['videos']);
}
if(isset($_GET['next'])) {
$current = intval($_GET['next']);
if($current > count($_SESSION['videos'])) {
$current = 0;
}
$_SESSION['curVid'] = $current;
}
$current = $_SESSION['curVid'];
$video = $_SESSION['videos'][$current];
$next = $_SESSION['curVid']+1;
echo "Next video";