I can not find the error that this Heredoc (PHP) produces

0

The code is this:

<div class="panel-body">
<?php
$login_form = <<<EOD
  <form role="form" name="login" id="login" method="POST" action="check_login.php">
      <div class="form-group">
          <label for="exampleInputEmail1">Usuario:</label>
          <input type="text" class="form-control" name="username" id="username">
      </div>
      <div class="form-group">
          <label for="exampleInputPassword1">Contraseña:</label>
          <input type="password" class="form-control" name="password" id="password">
      </div>                                    
      <button type="submit" class="btn btn-info">Ingresar</button>
  </form>
  EOD;
$msg = $_GET['msg'];  //GET the message
if($msg!='') echo '<p>'.$msg.'</p>'; //If message is set echo it
echo "<h1>Please enter your Login Information</h1>";
echo $login_form;
?>
</div>

The error that returns to me is:

  

Parse error: syntax error, unexpected '' ( T_ENCAPSED_AND_WHITESPACE ), expecting identifier ( T_STRING ) or variable ( T_VARIABLE ) or number ( T_NUM_STRING ) on line 91

Line 91 is:

$msg = $_GET['msg'];  //GET the message

I was reading that the EOD; final% does not have to have spaces and it does not have it.

    
asked by Carlos 31.01.2017 в 09:23
source

2 answers

1

The problem is that the EOD or any string you use as a delimiter must occupy the entire line excluding the ; :

  

Warning :

     

It is very important to note that the line with the   closure identifier must not contain any other character, except   a semicolon (;). This, in particular, means that the identifier should not be indented , and that there should be no space or   tabulation before or after the semicolon.

Do not be confused by the fact that the problem is giving you the line immediately after the real problem.

So even if you have indented PHP code, the delimiter string must start at the beginning of the line:

<div class="panel-body">
    <?php                       
    $login_form = <<<EOD        
    <form role="form" name="login" id="login" method="POST" action="check_login.php">
        <div class="form-group">    
            <label for="exampleInputEmail1">Usuario:</label>
            <input type="text" class="form-control" name="username" id="username">
        </div>                      
        <div class="form-group">    
            <label for="exampleInputPassword1">Contraseña:</label>
            <input type="password" class="form-control" name="password" id="password">
        </div>                      
        <button type="submit" class="btn btn-info">Ingresar</button> 
    </form>                     
EOD;
/* ^^ debe comenzar al inicio de la línea, sin sangrado */
    $msg = $_GET['msg'];  //GET the message
    if($msg!='') echo '<p>'.$msg.'</p>'; //If message is set echo it 
    echo "<h1>Please enter your Login Information</h1>";
    echo $login_form;           
    ?>                          
</div>
    
answered by 31.01.2017 в 12:38
0

It is very possible that what is happening to you is that the token EOD final% is not stuck to the left (without spaces), which is a requirement of heredoc as you comment.

    
answered by 31.01.2017 в 09:44