hoochblues Posted May 28, 2008 Share Posted May 28, 2008 New. Simple question. A lot of times I will see an example coded something like this <body> <?php if($this->values) { ?> <h3>You just submitted the following values:</h3> <ul> <?php foreach ($this->values as $value) :?> <li> <?= $this->escape($value); ?> </li> <?php endforeach; ?> </ul> <?= $this->form; ?> </body> </html> Actually this example didn't work. But the getting it to work isn't my question. To my addled brain it is easier for me to think of it as this. <?php if ($this->values) { echo "<h3>You just submitted the following values:</h3>"; echo "<ul>"; foreach ($this->values as $value) { echo "<li>"; echo $this->escape($value); echo "</li>"; } } echo $this->form; ?> The former lays everything out with small PHP code chunks embedded into HTML. The latter is one big PHP code chunk that echos the HTML. Is the second manner that much less efficient? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/107707-newbie-re-php-coding/ Share on other sites More sharing options...
DarkWater Posted May 28, 2008 Share Posted May 28, 2008 It's not less efficient, it's just that people are too lazy to escape quotes, so they exit out of PHP. =P Btw, you can use a templating engine for something like this if you want. Check out Smarty. Quote Link to comment https://forums.phpfreaks.com/topic/107707-newbie-re-php-coding/#findComment-552159 Share on other sites More sharing options...
.josh Posted May 28, 2008 Share Posted May 28, 2008 It's argued that the less php code and the more straight html means less server processing and more client processing, which means faster page load times. edit: while I'm not denying that idea at face value, 99.999% of the time we're talking about time and overall scale so small that nobody really truly should care unless they are anal retentive. I personally hate that style of coding. If I have extended html code I will occasionally wrap it up with HEREDOC Quote Link to comment https://forums.phpfreaks.com/topic/107707-newbie-re-php-coding/#findComment-552173 Share on other sites More sharing options...
hoochblues Posted May 28, 2008 Author Share Posted May 28, 2008 It's not less efficient, it's just that people are too lazy to escape quotes, so they exit out of PHP. =P Btw, you can use a templating engine for something like this if you want. Check out Smarty. Thanks! The example actually came from the Zend Framework quickstart. I was playing around with that. Quote Link to comment https://forums.phpfreaks.com/topic/107707-newbie-re-php-coding/#findComment-552174 Share on other sites More sharing options...
DarkWater Posted May 28, 2008 Share Posted May 28, 2008 I do the same as Crayon Violent. I absolutely hate going in and out of PHP to save myself from typing 2 extra \'s. >_> It makes the code look ridiculous. Quote Link to comment https://forums.phpfreaks.com/topic/107707-newbie-re-php-coding/#findComment-552187 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.