嵌入随机命名的MP3 [英] Embed randomly named MP3

查看:62
本文介绍了嵌入随机命名的MP3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

<embed src="/sound/lowyourchicken.mp3" 
width="140" height="40" autostart="true" loop="TRUE"> 
</embed> 

我希望.mp3的src考虑到/sound/目录中有许多随机命名的.mp3文件,并且每次打开页面时都随机选择一个.有什么线索吗?

I would like the src for the .mp3 to take in to account that there are many randomly named .mp3 files in the /sound/ directory, and to choose one at random each time the page is opened. Any clues for me?

我的服务器已启用PHP,但我想使其尽可能简单.

My server is PHP enabled but I'd like to keep this as simple as possible.

推荐答案

这应该做到:

$files = glob("/path/to/directory/*.mp3");
$random = array_rand($files)

然后执行以下操作:

<embed src="<?php echo $random ?>" 
width="140" height="40" autostart="true" loop="TRUE"> 
</embed> 

这篇关于嵌入随机命名的MP3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆