Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Senior Coder
    Join Date
    Jul 2005
    Location
    UK
    Posts
    1,051
    Thanks
    6
    Thanked 13 Times in 13 Posts

    Command for stopping PHP dead

    Is there a simple command that will stop PHP executing in it's tracks? I'm writing a fairly complex script with many nested loops, and at some point if a condition is met I'd like the script to stop and output some HTML without executing the tail end of the loops.

    Something like break() but for if/else loops, basically.

  • #2
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Stop forever, or just exit the if/else loop?

    To stop the script forever, use die() or exit().

    HTH
    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #3
    New Coder
    Join Date
    Aug 2007
    Location
    Seattle, WA
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What whizard said -- To stop the script - just use this:
    Code:
    if($statement == $statement){
    echo "You failed to meet the requirements."; exit; 
    }elseif($statement == $statement){
    die("You failed to meet the requirements.");
    }else{
    echo "";
    }

  • #4
    Senior Coder
    Join Date
    Jul 2005
    Location
    UK
    Posts
    1,051
    Thanks
    6
    Thanked 13 Times in 13 Posts
    Heh, I like how I virtually answered my own question. "Stop PHP dead" indeed...

    die() of course is right in front of my nose virtually all the time :-).

  • #5
    New Coder
    Join Date
    Aug 2007
    Location
    Seattle, WA
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    LOL. Haha. =p
    Josh/12/PHP/MySQL/Some Javascript/Some AJAX/HTML/CSS/Some Photoshopping/Learning C++


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •