Jump to content

Going to 'Explode'!!


alant

Recommended Posts

Still trying to get my head around php.
[code]<?php
function 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

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]
<?php
function 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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.