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.

1
  • 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 <?php & ?> tags even if include call already enclosed in these tags. Commented Aug 3, 2012 at 16:01

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.