nycmattw Posted May 30, 2010 Share Posted May 30, 2010 I want to translate a whole html template into php without echoing every single line. How should I do this? Link to comment Share on other sites More sharing options...
0 Dodzey Posted May 30, 2010 Share Posted May 30, 2010 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. Link to comment Share on other sites More sharing options...
0 Colin-uk Veteran Posted May 30, 2010 Veteran Share Posted May 30, 2010 i usually find its easier to put the php into the html file :p just make sure the php code is in php tags. Hendrick 1 Share Link to comment Share on other sites More sharing options...
0 c3ntury Posted May 30, 2010 Share Posted May 30, 2010 just make sure the php code is in php tags. You would be surprised how many amateur sites don't have those tags ;) Makes the layout a mess. Link to comment Share on other sites More sharing options...
0 nycmattw Posted May 30, 2010 Author Share Posted May 30, 2010 I mean that my php file that is part html and part php. I just want it to be wholly php and pure php. Link to comment Share on other sites More sharing options...
0 That Guy Veteran Posted May 30, 2010 Veteran Share Posted May 30, 2010 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. Link to comment Share on other sites More sharing options...
0 Baines Posted May 30, 2010 Share Posted May 30, 2010 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. <?php $number = 5; ?> <div id="header">Header</div> <?php if ($number == 5) : ?> <strong>The number is:</strong> 5 <?php else : ?> The number isn't 5. <?php endif; ?> <div id="footer">Footer</div> Link to comment Share on other sites More sharing options...
0 Colin-uk Veteran Posted May 30, 2010 Veteran Share Posted May 30, 2010 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: 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. Link to comment Share on other sites More sharing options...
0 nycmattw Posted May 30, 2010 Author Share Posted May 30, 2010 But you see if I have html and use the switch function or whatever its called you get this: http://lacydic.com/?action=support Edit: You are only supposed to see the live chat and ticket buttons, not the whole index file. Link to comment Share on other sites More sharing options...
0 nub Posted May 31, 2010 Share Posted May 31, 2010 Firefox can't find the server at www.lacydic.com. Link to comment Share on other sites More sharing options...
0 nycmattw Posted May 31, 2010 Author Share Posted May 31, 2010 Yea the server got hacked so it'll take a while Link to comment Share on other sites More sharing options...
0 Hendrick Posted May 31, 2010 Share Posted May 31, 2010 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. Link to comment Share on other sites More sharing options...
0 nycmattw Posted May 31, 2010 Author Share Posted May 31, 2010 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. Link to comment Share on other sites More sharing options...
0 Ahmed Samir Posted May 31, 2010 Share Posted May 31, 2010 You would be surprised how many amateur sites don't have those tags ;) Makes the layout a mess. :huh: seriously? 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. Yea the server got hacked so it'll take a while :laugh: Way to go! Link to comment Share on other sites More sharing options...
Question
nycmattw
I want to translate a whole html template into php without echoing every single line. How should I do this?
Link to comment
Share on other sites
13 answers to this question
Recommended Posts