Page 1 of 1

Need some ideas for breaking out of script

Posted: Thu May 20, 2010 3:26 am
by Jackolantern
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!

Re: Need some ideas for breaking out of script

Posted: Thu May 20, 2010 8:32 am
by Jony
I think that you could use return instead.

Re: Need some ideas for breaking out of script

Posted: Thu May 20, 2010 1:03 pm
by Noctrine
Return for ending functions, Break for ending loops or a switch.

Re: Need some ideas for breaking out of script

Posted: Thu May 20, 2010 2:30 pm
by hallsofvallhalla
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;
}

Re: Need some ideas for breaking out of script

Posted: Thu May 20, 2010 5:18 pm
by Jackolantern
Sounds good, thanks!

Re: Need some ideas for breaking out of script

Posted: Thu May 20, 2010 5:21 pm
by hallsofvallhalla
haha just seen that dodie is sounding like "doodie" when it was meant to be do die, hehe

Re: Need some ideas for breaking out of script

Posted: Fri May 21, 2010 3:56 am
by Jackolantern
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 :?