Jump to content

Does list() have a limit?


smith.james0

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
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.