首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于URL参数的PHP包含

基于URL参数的PHP包含
EN

Stack Overflow用户
提问于 2014-10-02 13:36:32
回答 1查看 805关注 0票数 0

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

1.php 2.php 3.php . 30.php

URL如下所示:

Www.example.com?包括=1-4-14-20-29

我需要这样的东西,但我知道这是无效的:

代码语言:javascript
复制
$include = @$_GET['include'];   // hyphen separated list of file names.

$arr = explode("-", $include);  //explode into an array
foreach ($arr as $filename) {
include $filename."php";

}

我想得到的是:

代码语言:javascript
复制
<php
include '1.php';
include '4.php';
include '14.php';
include '20.php';
include '29.php';
?>

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-02 13:44:27

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

代码语言:javascript
复制
<?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";
}

?>

编辑

哦,对不起,刚才看到我误解了你的问题,你不是在找范围,而是找个别的电话。那么这个是给你的:

代码语言:javascript
复制
<?php
$include = $_GET['include'];   // hyphen separated list of file names.

$arr = explode("-", $include);  //explode into an array
foreach ($arr as $filename) {
include $filename.".php";
}

?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26162073

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档