Jump to content

Stop PHP parsing but not HTML


nloding

Recommended Posts

I'm not sure how to accomplish this, if I can at all.

Let say I have an if loop that checks for errors, and when it does, I want the PHP script to stop, but I want the HTML to continue ... for instance.

I currently have an if statement checking for errors on form submission, and the if statement ends with "exit;".  Below the PHP, I have a standard HTML <div> that is my footer, and I want that displayed at all times.  If the exit command is processed, the footer div isn't displayed.

Other than putting the footer div in it's own include file and including it after each "exit;" command, is there a way to have the PHP stop processing and just skip to the HTML beneath it?

[code]
<p>This is always displayed, regardless of the error!</p>
<?php
$errormessage = true;
if($errormessage){
  echo "Oops!  Now the footer paragraph is gone!";
  exit;
}
?>
<p id="footer">Oh no!  If that error is there, I'm gone!</p>
[/code]

I think that code should illustrate what I mean :)
Link to comment
https://forums.phpfreaks.com/topic/36002-stop-php-parsing-but-not-html/
Share on other sites

Well one way is to make the entire HTML below the script a variable and display it before exit;

My personal way of doing it is I completly seperate HTML and PHP for reasons like this. My way I have all my PHP in the root and HTML in .PHP documents in a templates folder

So that way here is how mine works:

[code]
if ( $errormessage ) {
   $resulttext = "Oh snap something hit the fan!"; //You can call an echo in your HTML called resulttext so you can give the error messages
   require ('templates/myhtmlpage.php');
   die;
}
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.