"." operator to join two strings...
-
Why do you ask if I've included ALL the code? I've included some files in order not to repeat code. There are plenty of situations in which I'm using this. Do I'm missing something? Here we go... I know it seems incredible but it is what it happens... I'm doing something like:
$path = DOC_ROOT.'/';
echo $path; Here it works well.but if I'm doing something like:
$path = DOC_ROOT.'/';
$path2 = $path.'folderX'
$path3 = $path.'folderY'include ($path.file1.php);
include ($path2.file9.php);here it fails in each include and if I'm trying to get echoed the result it also fails. As I'm using the paths to include code, I've misunderstood at the beginning... my fault... X|
[www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.
modified on Saturday, March 19, 2011 9:19 AM
don't you mean
include ($path.'file1.php'); // added single quotes
include ($path2.'file9.php'); -
Why do you ask if I've included ALL the code? I've included some files in order not to repeat code. There are plenty of situations in which I'm using this. Do I'm missing something? Here we go... I know it seems incredible but it is what it happens... I'm doing something like:
$path = DOC_ROOT.'/';
echo $path; Here it works well.but if I'm doing something like:
$path = DOC_ROOT.'/';
$path2 = $path.'folderX'
$path3 = $path.'folderY'include ($path.file1.php);
include ($path2.file9.php);here it fails in each include and if I'm trying to get echoed the result it also fails. As I'm using the paths to include code, I've misunderstood at the beginning... my fault... X|
[www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.
modified on Saturday, March 19, 2011 9:19 AM
another suggestion: if you know or can calculate your folder depth (currently requested script's distance from the web root) try this:
$sDepth='../../'; // for example
require_once($sDepth.'file1.php'); -
don't you mean
include ($path.'file1.php'); // added single quotes
include ($path2.'file9.php');Yes, I'm at home now without access to the code (using pseudocode here).
[www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.
-
Hello all, Here a novice trying to concatenate two strings without luck... :sigh: Note: The Document root is "www".
$PATH = $_SERVER['DOCUMENT_ROOT'].'/';
This works wonderfully as I can see "www/".echo $PATH.'FILE.php';
This should show something like: "www/FILE.php"; but it shows "wwwFILE.php". Why is this happening? Any idea on what I'm doing that is not correct? Thank you in advance. :thumbsup:[www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.
Your code works fine for me (XAMPP 1.6.6a; PHP 5.2.5). Look again Monday! :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
Your code works fine for me (XAMPP 1.6.6a; PHP 5.2.5). Look again Monday! :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
<?php
$path_root = $_SERVER['DOCUMENT_ROOT'].'/';echo $path_root;
include($path_root.'aaa.php'); // this one works well
include($path_root.'bbb.php'); // this one gives me the error * (see below).
?>* Error: : "Warning: include(C:/Program Files/EasyPHP-5.3.5.0/wwwbbb.php) [function.include]: failed to open stream: No such file or directory in C:\Program Files\EasyPHP-5.3.5.0\www\index.php on line 9 It seems to me that, for any unknown reason the last '/' is getting removed automatically after using it inside an include clause. :confused:
[www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.
-
<?php
$path_root = $_SERVER['DOCUMENT_ROOT'].'/';echo $path_root;
include($path_root.'aaa.php'); // this one works well
include($path_root.'bbb.php'); // this one gives me the error * (see below).
?>* Error: : "Warning: include(C:/Program Files/EasyPHP-5.3.5.0/wwwbbb.php) [function.include]: failed to open stream: No such file or directory in C:\Program Files\EasyPHP-5.3.5.0\www\index.php on line 9 It seems to me that, for any unknown reason the last '/' is getting removed automatically after using it inside an include clause. :confused:
[www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.
Three comments: 1. that looks like a bug then, in your PHP system. 2. why do you feel a need to specify an explicit path in an include? I never do that, I use relative paths. Wouldn't
include('aaa.php');
include('bbb.php');work well? 3. please try again with a backslash in $path_root. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
Three comments: 1. that looks like a bug then, in your PHP system. 2. why do you feel a need to specify an explicit path in an include? I never do that, I use relative paths. Wouldn't
include('aaa.php');
include('bbb.php');work well? 3. please try again with a backslash in $path_root. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
Luc Pattyn wrote:
that looks like a bug then, in your PHP system
:(( It had no sense to me... Strange behavior.
Luc Pattyn wrote:
why do you feel a need to specify an explicit path in an include?
Probably this is again a bug then... I've tried to use relative paths like '../aaa.php' and so on, but the problem here is that I'm using some files from different locations and those files seem to inherit (somehow) the original path... then the relative paths change depending on the file that is including the file that includes another file... Using the doc_root helps me avoiding this problem...
Luc Pattyn wrote:
please try again with a backslash in $path_root.
Done it already... it don't wants to work... X| Thank you for your answer! :thumbsup:
[www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.
-
Luc Pattyn wrote:
that looks like a bug then, in your PHP system
:(( It had no sense to me... Strange behavior.
Luc Pattyn wrote:
why do you feel a need to specify an explicit path in an include?
Probably this is again a bug then... I've tried to use relative paths like '../aaa.php' and so on, but the problem here is that I'm using some files from different locations and those files seem to inherit (somehow) the original path... then the relative paths change depending on the file that is including the file that includes another file... Using the doc_root helps me avoiding this problem...
Luc Pattyn wrote:
please try again with a backslash in $path_root.
Done it already... it don't wants to work... X| Thank you for your answer! :thumbsup:
[www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.
you're welcome. FYI: I typically use:
require\_once("includes/somename.php");
i.e. my pages are at the top level of the web site, my dependencies one level down. Never had a problem with it. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
<?php
$path_root = $_SERVER['DOCUMENT_ROOT'].'/';echo $path_root;
include($path_root.'aaa.php'); // this one works well
include($path_root.'bbb.php'); // this one gives me the error * (see below).
?>* Error: : "Warning: include(C:/Program Files/EasyPHP-5.3.5.0/wwwbbb.php) [function.include]: failed to open stream: No such file or directory in C:\Program Files\EasyPHP-5.3.5.0\www\index.php on line 9 It seems to me that, for any unknown reason the last '/' is getting removed automatically after using it inside an include clause. :confused:
[www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.
$path_root
is a global variable, so maybe something in the 'aaa.php' include (or another file included by that) is modifying it. -
$path_root
is a global variable, so maybe something in the 'aaa.php' include (or another file included by that) is modifying it.Nice suggestion, I tried this the first thing... searched for all the $path_root variables in the web site in order to find any inconsistence... The only thing it can happen here is that the include clause is removing the last / in the file path. I works once, it never works again.
[www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.
-
Hello all, Here a novice trying to concatenate two strings without luck... :sigh: Note: The Document root is "www".
$PATH = $_SERVER['DOCUMENT_ROOT'].'/';
This works wonderfully as I can see "www/".echo $PATH.'FILE.php';
This should show something like: "www/FILE.php"; but it shows "wwwFILE.php". Why is this happening? Any idea on what I'm doing that is not correct? Thank you in advance. :thumbsup:[www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.
PHP has two ways for specifying strings. single quotes '' double quotes "" $car = 'Holden'; $sq = 'My car is a $car'; //My car is a $car $dq = "My car is a $car"; //My car is a Holden With double quotes the variable is inserted. If you are using an array or want to seperate a variable in double quotes use braces. $array['tv_show'] = 'American Idol'; $br = "{$array['tv_show']} is terrible but {$car}'s are awesome"; for the example above use "{$_SERVER['DOCUMENT_ROOT']}/FILE.php"; It may be that you are using windows and the interpreter could be swapping a '/' for '\'.