alant Posted December 11, 2006 Share Posted December 11, 2006 Still trying to get my head around php. [code]<?phpfunction path(){$a=($_SERVER['SCRIPT_NAME']);$b=explode("/",$a,-1);print "C:\\text";foreach ($b as $c) { print ($c . "\\"); }}$p=path();echo $p;?>[/code]I have made my website to call .txt files which are stored in a different root dir from my website but in an identical folder structure. e.g my index php is in 'C:\www\resources\index.php' and the text file is in "C:\text\resources\filename.txt". The code above succesfully returns on screen the string: "C:\text\resources\"I then want to use that string with the include function e.g: [code]<?php include($p . "filename.txt")?>[/code]However the include code doesn't seem to work with variables. Anyone have any ideas? Link to comment https://forums.phpfreaks.com/topic/30178-going-to-explode/ Share on other sites More sharing options...
trq Posted December 11, 2006 Share Posted December 11, 2006 You might want to get into the habbit of formatting your code so its readable. Then, you need the function to [i]return[/i] the value, not just simply print it. eg;[code]<?phpfunction path() { $a = $_SERVER['SCRIPT_NAME']; $b = explode("/",$a,-1); $c = "C:\\text"; foreach ($b as $c) { $c .= "\\"; } return $c;}$p = path();include $p . "filename.txt";?>[/code] Link to comment https://forums.phpfreaks.com/topic/30178-going-to-explode/#findComment-138744 Share on other sites More sharing options...
alant Posted December 11, 2006 Author Share Posted December 11, 2006 Ok thanks for that. It is partially working with that code. However if i use a folder more than one level deep then return $c only returns the last folder in the array. How can I get it to return multiple values? e.g if i have another php file inside [i]C:\resources\folder1[/i] the code only returns the value of [i]C:\text\folder1\[/i] rather than the full path of [i]C:\text\resources\folder1\[/i]. Also is there any php equivalent of the DOS command: 'CD\'?Thanks, Link to comment https://forums.phpfreaks.com/topic/30178-going-to-explode/#findComment-138767 Share on other sites More sharing options...
trq Posted December 11, 2006 Share Posted December 11, 2006 Really there are much better ways of going about what it seems you are trying to do. Take a look at the $_SERVER['DOCUMENT_ROOT'] variable and work from there.And no, DOS is an operating system, php is not and has no use for a [i]command[/i] cd. Link to comment https://forums.phpfreaks.com/topic/30178-going-to-explode/#findComment-138769 Share on other sites More sharing options...
alant Posted December 11, 2006 Author Share Posted December 11, 2006 Thanks, $_SERVER['DOCUMENT_ROOT'] was the sort of thing I was meaning. However now I have another problem it doesn't appear to have a value. phpinfo says there is no value for doc_root and using: echo $_SERVER['DOCUMENT_ROOT'] returns nothing. Link to comment https://forums.phpfreaks.com/topic/30178-going-to-explode/#findComment-138777 Share on other sites More sharing options...
trq Posted December 11, 2006 Share Posted December 11, 2006 Thats unusuall. This would be a server configuration issue, what server and OS are you using? Link to comment https://forums.phpfreaks.com/topic/30178-going-to-explode/#findComment-138780 Share on other sites More sharing options...
alant Posted December 11, 2006 Author Share Posted December 11, 2006 Using IIS6 on Windows 2003 Server. With PHP 5.2 ISAPI installed. It's also configured to host multiple websites. I just attempted to do another echo on one of the other websites and it returned 'C:\www'. However looking through the config for each website they don't appear to be set any differently. ??? Link to comment https://forums.phpfreaks.com/topic/30178-going-to-explode/#findComment-138782 Share on other sites More sharing options...
trq Posted December 11, 2006 Share Posted December 11, 2006 Sorry, Ive never worked with php in IIS or Windows. The php manual states that the $_SERVER['DOCUMENT_ROOT'] variable is....[quote]The document root directory under which the current script is executing, as defined in the server's configuration file.[/quote]Sorry, but I can't help you. Link to comment https://forums.phpfreaks.com/topic/30178-going-to-explode/#findComment-138800 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.