vendlus Posted September 26, 2003 Posted September 26, 2003 Is it better to have all of your HTML echo'ed to the screen or jump in and out of php to code your HTML straight without needing echo?? Does it affect the processing speed enough to matter when the server has to gkepp getting into and out of php mode?? (I hope this question makes sense, if not, I'll try and post an example.) Quote
TCH-Don Posted September 26, 2003 Posted September 26, 2003 One of the great uses for echo is for conditional statments. As in if condition{ echo series of html} else{echo other html} I do not think it is nessary to echo all the html. But as to speed, I don't think it will matter on the super fast severs here, LOL But that is just my opinion. Quote
vendlus Posted September 26, 2003 Author Posted September 26, 2003 Ok, I didn't think it would effect enough to make much difference. Thanks. Rock Sign Quote
borfast Posted September 26, 2003 Posted September 26, 2003 Hi vendius. As turtle sad, speed won't be a problem, especially here at TCH As for the other question, if I have to output some data in the middle of my HTML, I like to do it "inline", like so ><!-- Lots of HTML code here --> <p>Hello. Your name is <?php echo $name; ?> and you are <?php echo $age ?> years old.</p> <!-- Lots of HTML code here --> I prefer that method, unless I have a huge amount of PHP code to put or have to break out of the PHP code lots of times. In such cases, I do it this way: ><!-- Lots of HTML code here --> <p> <?php if($age > 100) { ?> You are old! <?php } else { ?> You are not that old. <?php } ?> <!-- continue HTML code here --> <?php //do other PHP stuff here ?> <!-- mode HTML code here --> ....... You can break out of "PHP mode" right in the middle of an if statement and output whatever HTML you want for that condition. And you don't need to worry about escaping special characters, because you're not in PHP mode but in HTML mode. Let me know if this helps Quote
vendlus Posted September 26, 2003 Author Posted September 26, 2003 Thanks borfast. I do a mix of styles depending on how much php or html I have like you mentioned. I've just always wondered if technically I should be chosing one way other another. Thanks for your help. Quote
arvind Posted September 27, 2003 Posted September 27, 2003 sorry this is a realy newbie question what does this echo do. I just created a page with the code above but nothign happened only showed me : Hello. Your name is and you are years old. Quote
Deverill Posted September 27, 2003 Posted September 27, 2003 $name and $age are variables that have to be filled elsewhere. It could be a form that asks you to input that info or even a cookie saved from when it asked you last time. Just to see what happens, after the <?php put $name="arvind"; $age=109; and it should work if I haven't made a stupid PHP mistake Quote
vendlus Posted September 28, 2003 Author Posted September 28, 2003 echo simply copies what you have written into the html the user gets. so typing this in php.... >echo("<h1>Header for page</h1>"); is the same as typing this in html ><h1>Header for page</h1> --------------------------------- It's useful for when you want to dynamically update a page or have a form or something that you can't do in standard html. Quote
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.