scott212 Posted January 21, 2007 Share Posted January 21, 2007 If I've got a condition that outputs different blocks of html based on the condition. If it outputs a modest amount of html, is there a better way to collect the html than just escaping it all and echoing it? It becomes hard to manage and ugly all escaped like that. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 21, 2007 Share Posted January 21, 2007 [code]<?phpif($x){ ?><html here><?php}else{ ?><more html><?php}?>[/code] Quote Link to comment Share on other sites More sharing options...
trq Posted January 22, 2007 Share Posted January 22, 2007 You could use the 'here document' syntax. eg;[code]<?php$foo = 'this is foo';echo <<<END<html> <head> <title>$foo</title> </head> <body> <p>hello world!</p> </body></html>END;?>[/code] Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted January 22, 2007 Share Posted January 22, 2007 You can do this and not have to escape anything:[code]<?phpprint<<<HERE//PUT ALL HTML HEREHERE;?>[/code] Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted January 22, 2007 Share Posted January 22, 2007 Woah, triple posts! haha Quote Link to comment Share on other sites More sharing options...
scott212 Posted January 22, 2007 Author Share Posted January 22, 2007 that works?? I didn't think you could break the stream inside the condition! Edit: Wow! that was fast. All excellent suggestions I've never seen used anywhere. Thanks! Quote Link to comment Share on other sites More sharing options...
trq Posted January 22, 2007 Share Posted January 22, 2007 The only things you can't break in and out of php for are function and class definitions. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 22, 2007 Share Posted January 22, 2007 thorpe: you can break out of functions, unless I misunderstand you. You can dofunction foo(){ $bar = 1; ?><p>Hi</p><? return $bar;} Quote Link to comment Share on other sites More sharing options...
scott212 Posted January 22, 2007 Author Share Posted January 22, 2007 shizer, now I want to rewrite everthing I've been working on lately. Damn Quote Link to comment Share on other sites More sharing options...
trq Posted January 22, 2007 Share Posted January 22, 2007 Well there ya go. I didn't think you could do that. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.