Why won't the '<<<' code work in my code?

Discussion in 'PHP' started by Imozeb, Feb 22, 2010.

  1. #1
    I basicly need a way to print large amounts of html script to a specific portion of the screen. I tried this:

    //my code in <body> section

    PHP code:
    <p>
     <?PHP
      if ($vartest === 1)
      {
        $mystring = <<<test
        This is a test
        <p>
        test paragraph
        </p>
        test;
        echo ("$mystring");
      }
     ?>
    </p>
    Code (markup):

    It gives an error: 'unexpected $end' or something like that if I use the echo command. Why is this?

    Thanks.

    ~imozeb
     
    Imozeb, Feb 22, 2010 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    test; must be at the most left, without spaces or tabs.

    Regards :)
     
    koko5, Feb 22, 2010 IP
  3. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You need the closing test; to be at the start of the line for it to work with no spaces before it like so
    <p>
     <?PHP
      if ($vartest === 1)
      {
        $mystring = <<<test
        This is a test
        <p>
        test paragraph
        </p>
    test;
        echo ("$mystring");
      }
     ?>
    </p>
    PHP:
     
    JAY6390, Feb 22, 2010 IP
  4. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Oh! Okay. I thought PHP script ignored whitespace but I guess this one command is the exception. Thanks. :)
     
    Imozeb, Feb 22, 2010 IP