随机网址和标题与PHP

时间:2015-05-21 10:19:44

标签: php

我正在使用下面的代码来获取随机视频,我还需要添加标题。每个视频网址也必须有一个标题

有什么建议吗?

<?php 
$video_array = array 
('http://www.youtube.com/embed/rMNNDINCFHg', 
'http://www.youtube.com/embed/bDF6DVzKFFg', 
'http://www.youtube.com/embed/bDF6DVzKFFg'); 
shuffle($video_array);
$video = $video_array[0]; 
?>

<iframe width='1006' height='421' src='<?php echo $video; ?>' title='TITLE HERE' frameborder='0' allowfullscreen></iframe>

此致 艾琳

1 个答案:

答案 0 :(得分:8)

将图块存储在数组中并打印 -

<?php 
$video_array = array(
array('url' => 'http://www.youtube.com/embed/rMNNDINCFHg', 'title' => 'ABC'),
array('url' => 'http://www.youtube.com/embed/bDF6DVzKFFg', 'title' => 'DSF'),
array('url' => 'http://www.youtube.com/embed/bDF6DVzKFFg', 'title' => 'RYUY')
); 
shuffle($video_array);
$video = $video_array[0]; 
?>

<iframe width='1006' height='421' src='<?php echo $video['url']; ?>' title='<?php echo $video['title']; ?>' frameborder='0' allowfullscreen></iframe>