www.webdeveloper.com
Results 1 to 12 of 12

Thread: Unexpected '['

  1. #1
    Join Date
    Aug 2003
    Location
    In my house
    Posts
    4,004

    Unexpected '['

    Why doesn't this work?
    PHP Code:
    $file explode("\\\", getcwd())[3]; 
    I could do something like that in JS, like so
    Code:
    var foo = string.split("\\")[3];
    Last edited by Paul Jr; 04-11-2004 at 05:43 PM.
    Thousand different paths
    So many sterile ends
    I chose the Devil's path

    Never shall the sun kiss my face
    And caress me with it's burning light
    For I dwell in the shadows
    And sleep side by side with death

  2. #2
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    You have to use another variable.

    PHP Code:
    $file explode("\\\\"getcwd());
    $newFile $file[3];
    echo(
    $file[3] ."="$newFile); 
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  3. #3
    Join Date
    Aug 2003
    Location
    In my house
    Posts
    4,004
    I get an “Undefined offset: n” error when I do that; with n being the array element index.
    Thousand different paths
    So many sterile ends
    I chose the Devil's path

    Never shall the sun kiss my face
    And caress me with it's burning light
    For I dwell in the shadows
    And sleep side by side with death

  4. #4
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Originally posted by Paul Jr
    I get an “Undefined offset: n” error when I do that; with n] being the array element index.
    Come again?
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  5. #5
    Join Date
    Aug 2003
    Location
    In my house
    Posts
    4,004
    Click on the link in my sig.
    The two offending lines are the last two here:
    PHP Code:
    $dir explode("\\\", getcwd());
    $section = $dir[3];
    $file = $dir[4]
    ***EDIT***
    Incase the link doesn't work, this is what you'll see
    Notice: Undefined offset: 3 in c:\Apache\htdocs\index.php on line 55

    Notice: Undefined offset: 4 in c:\Apache\htdocs\index.php on line 56
    Thousand different paths
    So many sterile ends
    I chose the Devil's path

    Never shall the sun kiss my face
    And caress me with it's burning light
    For I dwell in the shadows
    And sleep side by side with death

  6. #6
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    That means there isn't a 3rd and 4th index. Use this:

    PHP Code:
    $dir explode("\\\\"getcwd());
    echo(
    "<pre>");
    print_r($dir);
    echo(
    "</pre>"); 
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  7. #7
    Join Date
    Aug 2003
    Location
    In my house
    Posts
    4,004
    Ah, I get it now. True, where the script is there isn't a 3rd or 4th index. Is there anyway to have $section and $file set to null or "" if the index doesn't exist?
    Thousand different paths
    So many sterile ends
    I chose the Devil's path

    Never shall the sun kiss my face
    And caress me with it's burning light
    For I dwell in the shadows
    And sleep side by side with death

  8. #8
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    PHP Code:
    $section "";
    $file "";
    if(isset(
    $dir[3]))
      {
    $section $dir[3];}
    if(isset(
    $dir[4]))
      {
    $file $dir[4];} 
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  9. #9
    Join Date
    Aug 2003
    Location
    In my house
    Posts
    4,004
    Thanks!
    Thousand different paths
    So many sterile ends
    I chose the Devil's path

    Never shall the sun kiss my face
    And caress me with it's burning light
    For I dwell in the shadows
    And sleep side by side with death

  10. #10
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Wait about twenty minutes before asking another question, okay? I gotta go get some Easter Pizza!
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  11. #11
    Join Date
    Aug 2003
    Location
    In my house
    Posts
    4,004
    Lol. Okay. I'm about done with asking questions for now anyways.
    Thousand different paths
    So many sterile ends
    I chose the Devil's path

    Never shall the sun kiss my face
    And caress me with it's burning light
    For I dwell in the shadows
    And sleep side by side with death

  12. #12
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Okay cool, I'm about done eating pizza now anyways.
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles