0
<?php

echo <<< END
<!DOCTYPE html>
<!--

-->
<html>
    <head>

        <title>Nav</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
         <!-- Fixed navbar -->
    <nav class="navbar navbar-default navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">

            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>

          <a class="navbar-brand" href="M.html">Clarity</a>
        </div>
        <div id="navbar" class="collapse navbar-collapse">
          <ul class="nav navbar-nav">
            <li class="active"><a href="#">Home</a></li>
            <li><a href="#about">About</a></li>

          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </nav>


_END;

?>

I am trying to include a navbar at the top of every page within my web application. I have created this file in order to include other pages to display the navbar. This doesn't work however, as I continue to get the following error:

Parse error: syntax error, unexpected end of file, expecting variable (T_VARIABLE) or heredoc end (T_END_HEREDOC) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN)

3 Answers3

1

Looking at the following resource: What is <<<_END?

The starting line

echo <<< END
<!DOCTYPE html>
<!--

Should be:

echo <<< _END
<!DOCTYPE html>
<!--
Community
  • 1
  • 1
Liam Sorsby
  • 2,912
  • 3
  • 28
  • 51
0

remove underscore and You probably have spaces after the terminator.

END;[space]

hit enter after END;

EDIT: It is very important to note that the line with the closing identifier must contain no other characters, except a semicolon (;). That means especially that the identifier may not be indented, and there may not be any spaces or tabs before or after the semicolon.

check here for more http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

SO-user
  • 1,458
  • 2
  • 21
  • 43
0

In my opinion a better way of doing this is like this:

<?php

// Some PHP code here
?>
<!DOCTYPE html>
<!--

-->
<html>
<head>

    <title>Nav</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
     <!-- Fixed navbar -->
<nav class="navbar navbar-default navbar-fixed-top">
  <div class="container">
    <div class="navbar-header">

        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>

      <a class="navbar-brand" href="M.html">Clarity</a>
    </div>
    <div id="navbar" class="collapse navbar-collapse">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Home</a></li>
        <li><a href="#about">About</a></li>

      </ul>
    </div><!--/.nav-collapse -->
  </div>
</nav>
<?php

// Continuing with PHP code
Michael Miriti
  • 301
  • 3
  • 14