Let say I have something like <?php //code ?> <html /> PHP: Is there a way to stop the PHP from running and just output the text. Like: <?php //code if ($condition) exitphp; ?> <html /> PHP:
do you mean what: <? if ($condition) { ?> <html /> <?} else { die();}?> in what example if $condition is something wan it will post <html /> else it will stop executing. Ore you want to execute html only if not condition, wan: <? if ($condition) { die(); }else {?> <html /> <?}?> In what example if condition, it will die, and if else it will post <html />.
Yeah, I know that I can do that but I was wondering if there is another way, without having to put the code in the if structure.
Possibly. If you used something like: $me = file_get_contents(__FILE__); // __FILE__ is a PHP defined constant $me = explode('?>', $me); // etc. echo $me[/* Continue here */]; PHP: Bit of a complicated way I think, but it can be done. Jay
I know this is a bit silly but if there are any more suggestions so... bump. I tried return but it worked like exit.
Hey this is nonsense , why do you need that ? if you need so separate PHP part from HTML <?php //code include('htmlfile.htm'); ?> PHP: so you call directly htmlfile.htm
I think return will do what you want if the PHP is in a separate file. I think this is what classic's post is getting at. PHP6 might make you happy. http://www.developertutorials.com/blog/php/goto-is-coming-to-php-14/
I was thinking maybe you'd be able to do something like this: <?php // stuff here if ($condition) break goto_html; // more code here goto_html: ?> <html> PHP: But I'm really not sure how it will work. Wow, goto is actually in PHP 5.3. http://wiki.php.net/doc/todo/undocumented#php_5.3
Here is how it can be done: 1) Using conditional statement like stated above (if/switch) 2) Keep the PHP code in a file, include it: <?php include('file.php'); ?> HTML PHP: In file.php, use return to stop executing the file from continuing. 3) Use a loop (for/while/do) and use continue/break to exit them. Peace,
Why don't you make a function which processes a file whih html , and call it just before exit(); Ex: function myfile($f){ ob_start(); include($f); $str= ob_get_contents(); ob_end_clean(); return $str; } Now in your php file: if ($condition){ echo myfile('somefile.php'); exit(); } The variable in php file will not be available in function, unless you set a global $var inside function. Easiest will be to add these variables to $GLOBALS and then call the function. regards
You can end the php usng ?> and than write the html and begin it again wherever u need it u can do it using break