我从这里得到了所需的ID变量(可能有1-6个值):
$new_product['ID'] =$row[2];我需要的是根据这个变量回显一个单独的'php-include‘,比如:
<?php include 'includes/size/prod/echo $row[2].php'; ?>其中包括/size/prod/1.php、includes/size/prod/2.php等
我不知道如何表达php中的“回声”。
发布于 2015-12-01 18:40:57
有几种方法:
//Concatenate array value in double quotes:
<?php include "includes/size/prod/{$row[2]}.php"; ?>
//Concatenate array value outside of quotes:
<?php include "includes/size/prod/".$row[2].".php"; ?>
//or, using single quotes:
<?php include 'includes/size/prod/'.$row[2].'.php'; ?>
//Concatenate variable (not array value) in double quotes:
<?php $page = $row[2]; include "includes/size/prod/$page.php"; ?>请参见:
发布于 2015-12-01 18:52:59
用这种技术包含你的PHP文件是非常危险的!!
您必须通过至少控制PHP包含的文件来防止这种情况发生
现在回答你的问题:
<?php
// ? $row2 contains more than 1 php file to include ?
// they are seperated by comma ?
$phpToInclude = NULL;
define(TEMPLATE_INCLUDE, 'includes/size/prod/');
if (isset($row[2])) {
$phpToInclude = explode($row[2], ',');
}
if (!is_null($phpToInclude)) {
foreach($phpToInclude as $f) {
$include = sprintf(TEMPLATE_INCLUDE . '%s', $f);
if (is_file($include)) {
// add validator here !!
include ($include);
}
else {
// file not exist, log your error
}
}
}
?>发布于 2015-12-01 19:01:40
敬请使用以下工作代码
$row[2] = '';
$file_name = !empty($row[2])?$row[2]:'default';
$include_file = "includes/size/prod/".$file_name.".php";
include($include_file);https://stackoverflow.com/questions/34018262
复制相似问题