-1
我想切换出目录中的文件名,所以我不必每次添加新的开关时,我添加新的内容...例如,如果文件名称是Domain_Hosting.php,我想使交换机/ url?op = Domain_hosting(减去.php)。下面的脚本作品最多foreach语句,我究竟做错了,请帮忙错误500当试图从数组中生成PHP开关
<?
require_once("C:/www/db.php");
stripslashes($_GET);
str_replace("%", '', $_GET);
$op = $_GET['op'];
$op = stripslashes($op);
$op = str_replace("/", '', $op);
$op = str_replace("%", '', $op);
$op = str_replace(".", '', $op);
$op = str_replace("+", '', $op);
$dir = './includes/content/';
$files1 = scandir($dir, 1);
$files1 = array_map(function($e){
return pathinfo($e, PATHINFO_FILENAME);
}, $files1);
switch($op) {
default:
require_once("includes/content/home.php");
break;
foreach ($files1 as &$file) {
case "$file":
require_once("includes/content/$file.php")
}
}
?>
你不能动态地构建' case这样的陈述。你将不得不重新考虑你的方法。 –
我重新考虑了上面的代码并解决了问题 – Click