Jump to content


Photo

Does list() have a limit?


  • Please log in to reply
4 replies to this topic

#1 smith.james0

smith.james0
  • Members
  • PipPipPip
  • Advanced Member
  • 122 posts

Posted 24 May 2006 - 07:21 PM

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\" /]

<?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";
}
?>

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

#2 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 24 May 2006 - 08:20 PM

Your problem lies elsewhere, I tested it, and it works fine with my dirstructure.

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

#3 smith.james0

smith.james0
  • Members
  • PipPipPip
  • Advanced Member
  • 122 posts

Posted 24 May 2006 - 08:36 PM

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.



#4 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 25 May 2006 - 07:00 AM

I'ts because you use '/' to explode the dirname. The first '/' represents 'root', so use this:

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

$root will be empty.

You could also trim-off the first slash:

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

But I recommend the first method.

#5 smith.james0

smith.james0
  • Members
  • PipPipPip
  • Advanced Member
  • 122 posts

Posted 25 May 2006 - 06:09 PM

Thanks for that! works great.

Thankyou

James




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users