I am taking some of my old PHP scripts I was working on before and using them in a new game. However, my old game had basically no design, and was just on a while page. The new game is being added to a template. In the old game, like in the video tutorials, I use the exit command to exit out of a script if the user enters bad information, an error occurs, or I otherwise need to stop execution.
My problem is that it ends execution of the page it its entirety, so the rest of the HTML layout does not get executed, and it becomes a stub, with half the page awkwardly missing.
Is there any command or any way to break out of a PHP script while finishing up the rest of the HTML on the page? I know it can be done logically, which is what I have been doing so far, but all the code editing is getting tiring. Thanks!
Need some ideas for breaking out of script
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Need some ideas for breaking out of script
The indelible lord of tl;dr
Re: Need some ideas for breaking out of script
I think that you could use return instead.
Re: Need some ideas for breaking out of script
Return for ending functions, Break for ending loops or a switch.
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Need some ideas for breaking out of script
or put your HTML in your PHP then run a function that outputs the remaining HTML then exits.
Code: Select all
echo " Hello Header!";
echo if(goingtodie == 1)
{
dodie();
}
function dodie()
{
echo "<center><b> finish out html at bottom of page </center></b>";
exit;
}
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Need some ideas for breaking out of script
haha just seen that dodie is sounding like "doodie" when it was meant to be do die, hehe
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Need some ideas for breaking out of script
hehe...doodie...
Sadly, PHP doesn't have a Try-Catch-Finally structure, as that would work perfectly in this case to ensure that the rest of the page was executed. PHP only has Try-Catch
Sadly, PHP doesn't have a Try-Catch-Finally structure, as that would work perfectly in this case to ensure that the rest of the page was executed. PHP only has Try-Catch

The indelible lord of tl;dr