0

here's what I'm wanting to do:

<? include 'header.php' ?>
some html
<? include 'footer.php' ?>

in header.php...

<? //bunch of code
if (something){
//some stuff here, but no close brace
?>

in footer.php....

<? } //close the if brace ?>

Is this possible? I keep getting parse errors.

Thanks.

Sumico
  • 47
  • 1
  • 2
  • 5
  • Most of the time I use `header.php` & `footer.php` is to generate the literal `header` & `footer` for a web-page. The php logic is confined to the files itself. You cannot extend it in between files. Although maybe you already know, include files **EVEN** need their `` tags even if include call already enclosed in these tags. – DavChana Aug 03 '12 at 16:01

1 Answers1

2

No, you can't do that. Your brackets all need to be in the same file.

If you want to conditionally include HTML, put your logic in the file that includes header.php and footer.php

<?php include 'header.php' ?>
<?php if (/* something */): ?>
some html
<?php else : ?>
some other html
<?php endif; ?>
<?php include 'footer.php' ?>

Also, don't use ASP-style (<? ?>) short-open tags. They're being deprecated. You can still use <?= ?> to output variables and such.

Here's an interesting conversation on that topic.

And here's the notes from the PHP manual.

Matt
  • 6,993
  • 4
  • 29
  • 50
  • 1
    Since when are short tags being deprecated? I agree that they shouldn't be used, but they're certainly not being removed from the engine. Do you have a source to back that up? – Leigh Aug 03 '12 at 16:04