PHP包含路径中的变量 [英] PHP include with a variable in the path

查看:549
本文介绍了PHP包含路径中的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我们构建的网站必须从本地开发服务器移植到测试服务器,然后移植到实时服务器。出于这个原因,我们创建了一个变量:

 <?php $ path ='/ _Folder _ / _ SubFolder_'; ?> 

当我们将网站从服务器移动到下一个网站时,我们的想法是简单地更改$ path定义改造到新的开发服务器。目前,在我们调用包含的每个页面上,我们写道:

 <?php include('../_ includes / _css .PHP'); ?> 

但我要做的是:

 <?php include($ path。'/ _ includes / _css.php'); ?> 

我希望的结果是:

 <?php include('/ _ Folder _ / _ SubFolder _ / _ includes / _css.php'); ?> 

我一直惨遭失败导致:


警告:include(/ 文件夹 / _ SubFolder _ / _ includes / _css.php)[function.include]:无法打开流:第15行的C:\Program Files \Apache Software Foundation \ Apache2.2 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ / blockquote>

其他问题我仍然需要通过调用../\"



来包含变量来源

 <?php include('../_ includes / _var.php'); ?> 

如果有人能够更深入地了解我如何更有效地做到这一点我将非常感激。非常感谢您花时间,耐心和努力回应。

解决方案

您需要显示以前的目录

 <?php include('../_ includes / _css.php'); ?> 

因为你有 ../
如果 css.php = / _ * 文件夹 * _ / SubFolder / _ includes / _css.php,然后你需要使用下一个代码:

 <?php $ path ='。/ _ Folder_ / _SubFolder_'; 
include($ path。'/ _ includes / _css.php'); ?>

否则首先显示文件的完整路径 _css.php


So we build websites that have to ported from local development servers, to a test server, then to a live server. For this reason we have created a variable:

<?php $path = '/_Folder_/_SubFolder_'; ?>

When we move the website from server to the next, the idea is to simply change the $path definition to retrofit to the new development server. Currently, on each page when we call an include we write:

<?php include('../_includes/_css.php'); ?>

but what I'm trying to do is to:

<?php include($path.'/_includes/_css.php'); ?>

my result I hope for is:

<?php include('/_Folder_/_SubFolder_/_includes/_css.php'); ?>

I've been failing miserably resulting in:

Warning: include(/Folder/_SubFolder_/_includes/_css.php) [function.include]: failed to open stream: No such file or directory in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\FREEDOM2012_FREEDOM2012_DEFAULT_\accommodations\guest-rooms.php on line 15

Other Issue I still need to include the variable source by calling "../"

<?php include('../_includes/_var.php'); ?>

if anybody has any insight into how I could do this more efficiently I would be most appreciative. Thank you very much for your time, patience and effort in responding.

解决方案

you need show previous directory from

<?php include('../_includes/_css.php'); ?>

becose you have "../". If your full path from "css.php" = /_*Folder*_/SubFolder/_includes/_css.php , then you need use next code:

<?php $path = './_Folder_/_SubFolder_';
include($path.'/_includes/_css.php'); ?>

else first show full path to file _css.php

这篇关于PHP包含路径中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆