【发布时间】:2018-03-18 22:16:49
【问题描述】:
我需要在我的 html 文件中实现这个 PHP,这会转到一个目录检查那里的文件并创建一个包含这些选项的组合框......现在我如何才能在我的 html 代码中的特定位置调用它。
<?php
$dir = 'xml/';
$exclude = array('somefile.php', 'somedir');
// Check to see if $dir is a valid directory
if (is_dir($dir)) {
$contents = scandir($dir);
echo '<select class="dropdown-toggle" id="combo">';
foreach($contents as $file) {
// This will exclude all filenames contained within the $exclude array
// as well as hidden files that begin with '.'
if (!in_array($file, $exclude) && substr($file, 0, 1) != '.') {
echo '<option>'. $file .'</option>';
}
}
echo '</select>';
}
else {
echo "The directory <strong>". $dir ."</strong> doesn't exist.";
}
?>
【问题讨论】:
-
问题如何将 PHP 添加到我的 html 表中? 让我相信您应该阅读基础知识
-
“我需要在我的html文件中实现这个php”,你的意思是反过来吗?
-
请注意 HTML 是由浏览器和服务器上的 PHP 解析和显示的。因此,您不能简单地在 HTML 中放置/调用一些 PHP 代码来执行某些操作...
-
听起来你没有PHP经验。这是一个正确的假设吗?如果是这样,听起来你需要一个基本的 PHP 教程,因为你所问的没有一个快速、简单的答案,你需要了解一些基础知识。您不只是“将 PHP 添加到 HTML 文件”。也许这是一个不错的起点:php.net/manual/en/tutorial.php
-
如果我运行这段代码,它就像一个魅力......但现在我需要将它包含在我的 html 代码中......我该怎么做?
标签: php html filesystems