基于URL参数的PHP Include


PHP Include based on URL parameters

我有一个目录,其中包含30个php和各种html块。我试图根据url的参数包括这些文件中的5-6个。这些文件的名称如下:

1.php2.php3.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';
?>

谢谢你能提供的任何帮助。

我会循环遍历数组,因此会取最小值和最大值,如下所示:

<?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";
}
?>