Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
I'm running PHP4 and for some reason, I can't get here doc strings to work. Here's what I have Code: <?php echo <<<EOT A sentence spanning in multiple lines. EOT ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Engineer
    Join Date
    Nov 2002
    Location
    Queens, NY
    Posts
    1,319

    Basic syntax


    I'm running PHP4 and for some reason, I can't get here doc strings to work. Here's what I have
    Code:
    <?php echo <<<EOT
    A sentence
    spanning in multiple
    lines.
    EOT
    ?>
    As far as I'm concerned, I'm following the rules of the language by specifiying the identifiers and the closing identier stands alone in a newline. Any ideas why I'm having parsing errors?
    The best things in life are free.

  2. #2
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    You haven't included a semicolon after EOT, right? That could be the error.

  3. #3
    Linux Engineer
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    796
    Why are you printing out text with EOT..do like this..

    Code:
    <?php 
    
    echo "Hello World \n";
    echo "Printing another line on a line under \n";
    echo "Printing this text on the same line";
    
    ?>
    If you want to handle chunks of text or arrays use for or while loops for that.

    Regards

    Regards

    Andutt

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Well, it _is_ easier to write heredocs instead of doing such things.

  6. #5
    Linux Engineer
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    796
    No its not good programming....
    Regards

    Andutt

  7. #6
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Now that depends on what programming language you're using. In shell scripting, it's most certainly good programming, and I can't say that there's anything wrong with it in PHP either. What do you have against it? In PHP, it's just another way of quoting, and there's not anything wrong with quoting.

  8. #7
    Linux Engineer
    Join Date
    Nov 2002
    Location
    Queens, NY
    Posts
    1,319
    Sorry for the late reponse but after checking my code, there is a semi colon after the closing identifer EOT.
    The best things in life are free.

  9. #8
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Are you sure? I just tried the following, and it worked perfectly for me.
    Code:
    <?php echo <<<EOT
    Test
    Test
    Test
    EOT;
    ?>

  10. #9
    Linux Engineer
    Join Date
    Nov 2002
    Location
    Queens, NY
    Posts
    1,319
    Well here's the thing. I installed the php4 package from debian. I double checked to see that this was v4 instead of v3 since this is only supported in v4. I'm using apache to look at this since I don't have the command line interpreter installed on the machine. Looking through the file httpd.conf, everything seems to be in place regarding php4 so I don't know what the problem is. Could it be that there is an option to turn this on during installation and that Debian's package left out this option?
    The best things in life are free.

  11. #10
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    I wouldn't think so, but who knows? Stranger things have happened, after all. Maybe you should try to install it from source instead?

Page 1 of 2 1 2 LastLast

Posting Permissions

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