• 0

Possible to translate HTML into PHP


Question

13 answers to this question

Recommended Posts

  • 0
  On 30/05/2010 at 20:56, gmbblokus said:

I want to translate a whole html template into php without echoing every single line. How should I do this?

You just put the HTML into the PHP file?

Anything not inside <?php ?> (or the short tags) won't be parsed by the PHP handler and will just be returned as given.

  • 0

I think I understand what you want. One solution is to store all your HTML in templates, and then create a class which loads templates, and concatenates them together (you will have to load them in the order they are to be displayed). Then you just echo the one single variable which all the HTML is stored in.

  • 0

Like Dodzey said, you can just put straight up HTML outside of the PHP tags and it will be rendered out. You can even end php tags in the middle of if statements for conditional HTML, without the need to echo it out.

&lt;?php $number = 5; ?&gt;
&lt;div id="header"&gt;Header&lt;/div&gt;
&lt;?php if ($number == 5) : ?&gt;
&lt;strong&gt;The number is:&lt;/strong&gt; 5
&lt;?php else : ?&gt;
The number isn't 5.
&lt;?php endif; ?&gt;
&lt;div id="footer"&gt;Footer&lt;/div&gt;

  • 0

the html usually provides the layout whilst the php provides the interactive part. if you take out the html you will just be left with the php bit and no layout.

the only way to "translate" html into php and get the same result is to echo/print it.

edit:

  Quote

I think I understand what you want. One solution is to store all your HTML in templates, and then create a class which loads templates, and concatenates them together (you will have to load them in the order they are to be displayed). Then you just echo the one single variable which all the HTML is stored in.

yeah you could do it this way, you can either keep all your html in 1 file and read out the seperate bits to fit around your php, or you can put each bit in a seperate file and read each file out.

you can use file_get_contents(); to read the contents of a whole file, or preg_match(); to read part of a file.

  • 0

Are you trying to set up the ?action=support part? You use the GET command, and if the value is set to support, display what you want inside the IF statement.

You need to make sure though what is after the equals sign (=) isn't someone trying to hack you though. Easy exploit.

  • 0

What would I use to fix the exploit? Also I'm not talking about if you can see my website whenever it is finished there is a row that appears to be above the index.php file whent he index.php file isn't supposed to exist in that url. It's hard to explain but when you see the website you'll know what i mean.

  • 0
  On 30/05/2010 at 21:05, c3ntury said:

You would be surprised how many amateur sites don't have those tags ;) Makes the layout a mess.

:huh: seriously?

  On 30/05/2010 at 21:07, gmbblokus said:

I mean that my php file that is part html and part php. I just want it to be wholly php and pure php.

:whistle: dude, just use includes() for the parts you use and be happy.

  On 31/05/2010 at 01:52, gmbblokus said:

Yea the server got hacked so it'll take a while

:laugh: Way to go!

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.