1

I'm trying to reuse code for a header of a site using php's "includes" statement.

In the index.php file (the home page) is:

<body>
<?php
include_once "includes/header.php";
?>
</body>

then header.php just has html, first few lines look like:

<?php

<nav class="navbar navbar-inverse">
 <div class="container-fluid">
 .....
?>

And I'm getting an error message saying:

Parse error: syntax error, unexpected '<', expecting end of file in header.php

Can somebody tell me what I'm missing, or maybe if there's a better way to do this?

  • Possible duplicate of [PHP parse/syntax errors; and how to solve them?](https://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) – aynber Jun 07 '18 at 17:43

1 Answers1

4

then header.php just has html

No it doesn't. It has PHP:

<?php // <---- Notice this

    <nav class="navbar navbar-inverse">
    <div class="container-fluid">
    .....
?>

And it's syntactically invalid PHP, which is what the error is telling you. If that file truly doesn't have any PHP code, remove the <?php ?> tags:

<nav class="navbar navbar-inverse">
<div class="container-fluid">
.....

If it does have PHP code then you'll need to wrap only the PHP code in <?php ?> tags, not the HTML.

David
  • 208,112
  • 36
  • 198
  • 279
  • That worked, thanks. I'll accept the answer once time limit is over –  Jun 07 '18 at 17:42