Page 2 of 4

Re: HTML within PHP

Posted: Sun Feb 07, 2010 10:38 pm
by Jackolantern
I have never even seen that method. How does it work, and why would you say it bogs the server down? Is it saving all of the text server-side with that method?

Re: HTML within PHP

Posted: Mon Feb 08, 2010 1:57 am
by Torniquet
i base my decission on how much php i am using when creating that part of a page.

if it is simple bits of code such as if,while,for loops, then i generally do all variable storing at the start of the page then code the rest in html.

such as

Code: Select all


<?php
if($isfriend == FALSE){
?>
 
 HTML HERE

<?php
}
?>

OR

<a href="<?php echo $link; ?>">link</a>


if i am working with alot of both of them then i will print the html out ad style it asthough i was typing plain html.

Code: Select all


print"
<table>
  <tr>
    <td>
      blah blah blah
    </td>
  </tr>
</table>
";


Re: HTML within PHP

Posted: Mon Feb 08, 2010 4:54 am
by hallsofvallhalla
if you are saving all the text into a php variable then yes you are allocating server side memory for the variable.

Re: HTML within PHP

Posted: Mon Feb 08, 2010 1:12 pm
by Jackolantern
Doh! lol I didn't even see that $output variable for some reason. Very odd technique.

Re: HTML within PHP

Posted: Mon Feb 08, 2010 1:14 pm
by MAruz
Ok, so it's a performance hit doing it the way I described? Probably I wouldn't have noticed that as I develop the game :p

Re: HTML within PHP

Posted: Mon Feb 08, 2010 1:17 pm
by MAruz
Jackolantern wrote:Doh! lol I didn't even see that $output variable for some reason. Very odd technique.
Yeah it is, but I prefer it for some situations. Another detail to note about it is that if you view the source code of the web page, it will be formatted just as you write it within the output tags, even with indents. With PHP it all just get printed on the same line, making it hard to read the source.

If it's such a big issue with performance using this technique, I probably won't use it. Or is there a way to "release" the usage of memory right after processing the script?

Re: HTML within PHP

Posted: Mon Feb 08, 2010 1:40 pm
by Jackolantern
If you continuously use the same variable name it really shouldn't be too bad, because you will keep writing over your last variable. It is not going to be a huge performance hit, but it does seem somewhat unnecessary. If you were trying to speed up the processing of your pages if your site got popular, that would likely be on the "to remove" optimization list if it was used often. Compared to optimizing MySQL statements, it would likely matter very little though.

Re: HTML within PHP

Posted: Mon Feb 08, 2010 2:41 pm
by hallsofvallhalla
I wouldn't make it a habit to make the source readable. I hate the fact people can view source.

If you play on having hundreds+ users I would minimize the amount of variables you create.

Re: HTML within PHP

Posted: Mon Feb 08, 2010 9:47 pm
by Jackolantern
hallsofvallhalla wrote:I wouldn't make it a habit to make the source readable. I hate the fact people can view source. If you play on having hundreds+ users I would minimize the amount of variables you create.
I guess I still don't understand what you mean about the source, unless you are talking about JS. In the case of JS, you can at least get a bit more protection through obfuscation, although the JS obfuscators are nowhere near as good as they are for .NET and Java. However, for PHP I am not sure what you mean. The only thing viewable through the browser's "view source" option is pure HTML generated by PHP.

Re: HTML within PHP

Posted: Tue Feb 09, 2010 1:38 pm
by MAruz
Jackolantern wrote:
hallsofvallhalla wrote:I wouldn't make it a habit to make the source readable. I hate the fact people can view source. If you play on having hundreds+ users I would minimize the amount of variables you create.
The only thing viewable through the browser's "view source" option is pure HTML generated by PHP.
And it's that "view source" I was thinking about in my previous post, so the HTML looked a bit more tidy...