我有一个目录,其中包含30个php,包含各种html块。我试图根据url的参数包含这些文件的5-6个。这些文件的名称如下:
1.php 2.php 3.php . 30.php
URL如下所示:
Www.example.com?包括=1-4-14-20-29
我需要这样的东西,但我知道这是无效的:
$include = @$_GET['include']; // hyphen separated list of file names.
$arr = explode("-", $include); //explode into an array
foreach ($arr as $filename) {
include $filename."php";}
我想得到的是:
<php
include '1.php';
include '4.php';
include '14.php';
include '20.php';
include '29.php';
?>谢谢你能提供的任何帮助。
发布于 2014-10-02 13:44:27
我将循环遍历数组,因此将获得最小值和最大值,如下所示:
<?php
$include = $_GET['include']; // hyphen separated list of file names.
$arr = explode("-", $include); //explode into an array
# What's the min and max of the array?
$max = max($arr);
$min = min($arr);
# Just to see what's happening.
echo $max."-".$min;
# Start at the lowest value, and work towards the highest in the array.
for ($i = $min; $i <= $max; $i++) {
# Include the nth php file
include $i.".php";
}
?>编辑
哦,对不起,刚才看到我误解了你的问题,你不是在找范围,而是找个别的电话。那么这个是给你的:
<?php
$include = $_GET['include']; // hyphen separated list of file names.
$arr = explode("-", $include); //explode into an array
foreach ($arr as $filename) {
include $filename.".php";
}
?>https://stackoverflow.com/questions/26162073
复制相似问题