Need some ideas for breaking out of script

C++, C#, Java, PHP, ect...
Post Reply
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Need some ideas for breaking out of script

Post 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!
The indelible lord of tl;dr
Jony
Posts: 26
Joined: Tue May 11, 2010 3:34 pm

Re: Need some ideas for breaking out of script

Post by Jony »

I think that you could use return instead.
User avatar
Noctrine
Posts: 928
Joined: Thu Apr 23, 2009 9:57 pm

Re: Need some ideas for breaking out of script

Post by Noctrine »

Return for ending functions, Break for ending loops or a switch.
Jesse Dorsey
ProjectANI - Lead Developer Person
http://about.me/jessedorsey
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Need some ideas for breaking out of script

Post 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;
}
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Need some ideas for breaking out of script

Post by Jackolantern »

Sounds good, thanks!
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Need some ideas for breaking out of script

Post by hallsofvallhalla »

haha just seen that dodie is sounding like "doodie" when it was meant to be do die, hehe
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Need some ideas for breaking out of script

Post 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 :?
The indelible lord of tl;dr
Post Reply

Return to “Coding”