不带文件扩展名的 PHP 数组 - vimeo 视频
我终于设法让下面的 PHP 脚本工作...但后来我发现我实际上无法调用 vimeo 视频链接,因为它们没有文件扩展名,例如: http://vimeo.com/12345678
如果文件扩展名是图像文件,我使用的脚本会加载幻灯片,如果它是 flash 文件,它会加载swf,我的想法是如果文件扩展名是 .mov,则加载 vimeo iframe。所有文件名都在 work.txt 文件中。
我很困惑不知道该怎么办!有谁知道我可以添加什么以便该脚本可以加载 vimeo 视频吗?
<?php
$photos=file("work.txt");
$img = array('jpg', 'png', 'gif');
$vid = array('mp4', 'mov', 'mpg', 'flv');
$flash = array('swf');
foreach($photos as $image){
$item=explode("|",$image);
if($item[0]==$fields[0]){
$photo=trim($item[1]);
$ext = explode(".", $photo);
if(in_array($ext[1], $img))
{ echo "<div id='slider-wrapper'><div id='slider' class='nivoSlider'><img src='images/work/$photo' alt='' /></div></div>"; }
elseif(in_array($ext[1], $vid))
{ echo "<iframe src='http://player.vimeo.com/video/$photo' width='900' height='500' frameborder='0' webkitAllowFullScreen allowFullScreen></iframe>"; }
elseif(in_array($ext[1], $flash))
{ echo "<object id='myId' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='900' height='500'><param name='movie' value='$photo' />
<!--[if !IE]>-->
<object type='application/x-shockwave-flash' data='$photo' width='900' height='500'>
<!--<![endif]-->
<div>
<h1>Alternative content</h1>
<p><a href='http://www.adobe.com/go/getflashplayer'><img src='http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif' alt='Get Adobe Flash player' /></a></p>
</div>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>"; }
}
}
?>
I finally managed to get the PHP script below to work...but then I found that I actually can't call vimeo video links because they do not have a file extension eg: http://vimeo.com/12345678
The script I'm using loads a slideshow if the file extension is an image file, if it's a flash file it loads the swf, and my idea was to have a vimeo iframe load if the file extension was for example .mov. All of the filenames are in the work.txt file.
I am so confused about what to do! Does anyone have any ideas of what I could add so that this script can load vimeo videos?
<?php
$photos=file("work.txt");
$img = array('jpg', 'png', 'gif');
$vid = array('mp4', 'mov', 'mpg', 'flv');
$flash = array('swf');
foreach($photos as $image){
$item=explode("|",$image);
if($item[0]==$fields[0]){
$photo=trim($item[1]);
$ext = explode(".", $photo);
if(in_array($ext[1], $img))
{ echo "<div id='slider-wrapper'><div id='slider' class='nivoSlider'><img src='images/work/$photo' alt='' /></div></div>"; }
elseif(in_array($ext[1], $vid))
{ echo "<iframe src='http://player.vimeo.com/video/$photo' width='900' height='500' frameborder='0' webkitAllowFullScreen allowFullScreen></iframe>"; }
elseif(in_array($ext[1], $flash))
{ echo "<object id='myId' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='900' height='500'><param name='movie' value='$photo' />
<!--[if !IE]>-->
<object type='application/x-shockwave-flash' data='$photo' width='900' height='500'>
<!--<![endif]-->
<div>
<h1>Alternative content</h1>
<p><a href='http://www.adobe.com/go/getflashplayer'><img src='http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif' alt='Get Adobe Flash player' /></a></p>
</div>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>"; }
}
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在 URL 上使用 strpos 函数。
例如:
这将在您的字符串中搜索文本“vimeo.com”。
我在这里假设 $image 是完整的 URL。但它可能是$item,我无法从您提供的代码中真正看出
You could use the strpos function on the URL.
eg:
That will search your string for the text 'vimeo.com'.
I'm assuming here that $image is the full URL. But it might be $item, I can't really tell from the code you have provided