HTML within PHP

C++, C#, Java, PHP, ect...
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: HTML within PHP

Post 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?
The indelible lord of tl;dr
User avatar
Torniquet
Posts: 869
Joined: Sun Aug 02, 2009 6:18 am

Re: HTML within PHP

Post 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>
";

New Site Coming Soon! Stay tuned :D
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: HTML within PHP

Post by hallsofvallhalla »

if you are saving all the text into a php variable then yes you are allocating server side memory for the variable.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: HTML within PHP

Post by Jackolantern »

Doh! lol I didn't even see that $output variable for some reason. Very odd technique.
The indelible lord of tl;dr
User avatar
MAruz
Posts: 117
Joined: Fri Nov 20, 2009 12:31 pm

Re: HTML within PHP

Post 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
PHP, Java, JavaScript, HTML, CSS, XML, MySQL / Oracle
Photoshop, Illustrator
www.cuddly-zombie.com
User avatar
MAruz
Posts: 117
Joined: Fri Nov 20, 2009 12:31 pm

Re: HTML within PHP

Post 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?
PHP, Java, JavaScript, HTML, CSS, XML, MySQL / Oracle
Photoshop, Illustrator
www.cuddly-zombie.com
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: HTML within PHP

Post 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.
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: HTML within PHP

Post 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.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: HTML within PHP

Post 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.
The indelible lord of tl;dr
User avatar
MAruz
Posts: 117
Joined: Fri Nov 20, 2009 12:31 pm

Re: HTML within PHP

Post 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...
PHP, Java, JavaScript, HTML, CSS, XML, MySQL / Oracle
Photoshop, Illustrator
www.cuddly-zombie.com
Post Reply

Return to “Coding”