Jump to content

Archived

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

smith.james0

Does list() have a limit?

Recommended Posts

I am trying to us list() in the code below, the only problem with it is it only returns the first three varables, is there a limit on the list() function? I carn't find anything on php.net [img src=\"style_emoticons/[#EMO_DIR#]/excl.gif\" style=\"vertical-align:middle\" emoid=\":excl:\" border=\"0\" alt=\"excl.gif\" /]

[code]<?php
$absolute_path = pathinfo($_SERVER['SCRIPT_FILENAME']);
echo 'Path to this file: '.$absolute_path['dirname']."";


list($home,$account,$public,$visitors) = explode('/', $absolute_path['dirname']);

echo "$home <br> $account <br> $public <br> $visitors <br>";

if ( $visitors=='visitors' ) {
echo"yes";
}else{
echo "no";
}
?>[/code]

The idea of the code is to echo yes when it's in the visitors dir else echo no. I never get a value for $visitors even when it's in that dir

/home/*******/public_html/visitors

Can anyone help?

Thanks James

Share this post


Link to post
Share on other sites
Your problem lies elsewhere, I tested it, and it works fine with my dirstructure.

If you're really stuck, we need more info.

Share this post


Link to post
Share on other sites
Please take no notice of most of the contect of the page. apaert from the bottom bit. It's one of my script test pages, both files are the same, with the code above.

Share this post


Link to post
Share on other sites
I'ts because you use '/' to explode the dirname. The first '/' represents 'root', so use this:

[code]list($root,$home,$account,$public,$visitors) = explode('/', $absolute_path['dirname']);[/code]

$root will be empty.

You could also trim-off the first slash:

[code]list($home,$account,$public,$visitors) = explode('/', substr($absolute_path['dirname'],1,strlen($absolute_path['dirname'])));[/code]

But I recommend the first method.

Share this post


Link to post
Share on other sites

×

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.