Php 如何使用循环将文件名添加到代码中?
我想将所有文件添加到网页中的视频播放列表中Php 如何使用循环将文件名添加到代码中?,php,html,loops,for-loop,video,Php,Html,Loops,For Loop,Video,我想将所有文件添加到网页中的视频播放列表中 $d = dir("G:\ARIFIN\Picture\s"); while (($file = $d->read()) !== false){ echo $file . "<br>"; } $d->close(); 我想修改它以自动生成如下输出: <figcaption> <a href="aaaa.mp4" class="currentvid"> </
$d = dir("G:\ARIFIN\Picture\s");
while (($file = $d->read()) !== false){
echo $file . "<br>";
}
$d->close();
我想修改它以自动生成如下输出:
<figcaption>
<a href="aaaa.mp4" class="currentvid">
</a>
<a href="bbbb.mp4">
</a>
<a href="cccc.mp4">
</a>
<a href="dddd.mp4">
</a>
</figcaption>
但我不知道怎么做。我还是编程新手。这是一个解决方案:
<figcaption>
<?php
$d = dir("G:\ARIFIN\Picture\s");
$first = true;
while (($file = $d->read()) !== false){
if ( $first ) {
$first = false;
$currentvid = ' class="currentvid"';
} else {
$currentvid = '';
}
echo '<a href="' . $file . '"' . $currentvid . '>' . $file . '</a><br />';
}
$d->close();
?>
</figcaption>
您可以轻松地将PHP和HTML结合起来
<figcaption>
<?php
$d = dir("G:\ARIFIN\Picture\s");
$count=0;
while (($file = $d->read()) !== false){
if($count==0)
echo "<a href='{$file}' class='currentvid'/></a><br />";
else
echo "<a href='{$file}' ></a><br>";
$count++;
}
$d->close();
?>
</figcaption>
只需更改您的“echo”,它将显示链接而不是普通文本。它不起作用。。它只是播放了一个视频,然后结束,而不是继续下一个视频。无论如何,在
上面,我有
自动播放下一个视频和回显链接是两个完全不同的问题,好的先生。如果是这样的话,我建议你单独提问。你知道如何这样回应吗:
aaaa.mp4、bbbb.mp4等来自$file
它不起作用。。它只是播放了一个视频,然后结束,而不是继续下一个视频。无论如何,在
上面我有
<figcaption>
<?php
$d = dir("G:\ARIFIN\Picture\s");
$count=0;
while (($file = $d->read()) !== false){
if($count==0)
echo "<a href='{$file}' class='currentvid'/></a><br />";
else
echo "<a href='{$file}' ></a><br>";
$count++;
}
$d->close();
?>
</figcaption>
<?php $d = dir("G:\ARIFIN\Picture\s");
$str="<figcaption>";
$i=0;
while (($file = $d->read()) !== false){
$i++;
// echo $file . "<br>";
if($i==1){
$str.="<a href='$file' class='currentvid'/>";
}else{
$str.="<a href='$file'/>";
}
}
$d->close();
$str.="<figcaption>";
echo $str;
?>