NYCPHP Meetup

NYPHP.org

[nycphp-talk] DocumentRoot array oddness.

Ken Robinson kenrbnsn at rbnsn.com
Thu Sep 1 11:35:03 EDT 2005


At 11:21 AM 9/1/2005, leam at reuel.net wrote:
>I know I'm doing something wrong, just not sure what.
>
>Here's the output from the web page:
>
>DOCDIR is Array
>
>PHPDIR is /home/alba/php
>
>Here's the PHP bit that creates it:
>
>         $DOCDIR = explode("/", "$_SERVER[DOCUMENT_ROOT]");

The explode() function creates a array from a string using the 
delineator that you specify.

>         echo "<p>DOCDIR is $DOCDIR";

echo '<pre>';print_r($DOCDIR);echo '</pre>';

>         array_pop($DOCDIR);
>         array_push($DOCDIR , "php");
>         $PHPDIR = implode("/", $DOCDIR );
>         echo "<p>PHPDIR is $PHPDIR";
>         array_pop($DOCDIR);
>
>$DOCDIR *should* be /home/alba. Or even the acutal DocumentRoot as 
>alba is a v-host. It should *not* be "Array", and for the life of me 
>I can't see how $PHPDIR gets set with $DOCDIR in a mess.

$PHPDIR gets created correctly since everywhere else you are treating 
$DOCDIR as the array it is. The implode() fuction creates a string 
from an array putting the string you specify between each element in the array.

Ken Robinson 




More information about the talk mailing list