Welcome Guest, Not a member yet? Register   Sign In
Basic PHP question
#6

(08-06-2019, 04:22 PM)ronniebel Wrote: What's the difference between these two below? Why would one be better than the other? I'm new so I new to PHP, so an easy-to-understand answer would be helpful.

PHP Code:
<?php
echo '<h2>My Site</h2>'
?>
verses just straight html

Code:
<h2>My Site</h2>

Anything between the start and end processing instructions (the <?php and ?> tags) must be evaluated and converted into HTML (plain text) before being sent to the browser. So, the first example uses more server resources (memory, CPU cycles, etc) to get the same place as the second example.

IMO, writing HTML as PHP strings is often much more difficult than dropping into and out of PHP mode. There isn't any performance hit for switching modes. On the other hand, creating a bunch of strings and then concatenating them with PHP variables can require quite a lot of CPU cycles. It can be a lot harder to write error-free code and like-wise results in code that is hard for a human to comprehend.
Reply


Messages In This Thread
Basic PHP question - by ronniebel - 08-06-2019, 04:22 PM
RE: Basic PHP question - by includebeer - 08-06-2019, 05:14 PM
RE: Basic PHP question - by John_Betong - 08-06-2019, 11:12 PM
RE: Basic PHP question - by albertleao - 08-06-2019, 11:20 PM
RE: Basic PHP question - by includebeer - 08-07-2019, 02:57 AM
RE: Basic PHP question - by dave friend - 08-07-2019, 06:28 AM
RE: Basic PHP question - by John_Betong - 08-08-2019, 09:27 AM
RE: Basic PHP question - by includebeer - 08-08-2019, 10:12 AM
RE: Basic PHP question - by dave friend - 08-08-2019, 12:10 PM
RE: Basic PHP question - by kilishan - 08-08-2019, 02:27 PM



Theme © iAndrew 2016 - Forum software by © MyBB