php tutorials, php form validation
Archive Tutorials
Discussion Home
Login / Register

Board List
PHP programming
General

Links
How to save gas 25% or more
Marshall Reddick
Network Marketing Forums
Income Tax Help
Lose 10 Pounds in 3 Weeks
PHP Forum Script
Online Contest

Learn PHP in 47 hours!

Back to General

Search

Howto: Seperate HTML-code and PHP-code ? Howto: Seperate HTML-code and PHP-code ?

Howto: Seperate HTML-code and PHP-code ?

by hobbit on Sun 09/10/2006 02:21 PM

Hello,
i'm new here so i hope i'll do allright ;) Im not english but i think/hope/whatever you'll understand me nevertheless. 

Im learning PHP since two oder three months, and my problem/question is;
I'd like to sperate the php and the html code. I don't want the mess html/php, in a little project it's no problem, but in a 500-lines-project it isn't very good. I imagine it like that: 

You have a html-file, e.g: ( // are comments) 

 

#include  //I think thats clear;) 


shout() //php function, look at the php-part -.- 

 

Here comes the php-part: 

 

<?
shout()
{
echo "THATS IT";
}
?> 

 

I hope you understand what i mean; i have two files, one with the php-code and theother with the html-code. In the html code, there is a function-calling from the php-file. So it opens the php-file, jumps to the shout-function and prints THATS IT. 

So, i hope you know a idea how to realize that :) 

ps. i know that there are mistakes in the posted codes, they are pseudo-codes. Actually i'm a c++-programmer i think you noticed that ;) but yes...

[Reply] [Back to Top]

-

by hobbit on Sun 09/10/2006 02:24 PM

erm, it doesn't show the html-part :s here it is ;)
it was just the html-tags, head tags with the inclusing of php_part.php (you dont see that, too) and the body-tags with the "shout..." 


[Reply] [Back to Top]

huh?

by uclaboyz on Tue 09/12/2006 10:27 AM

Hi there, 

I don't quite understand what your question is.  Are you trying to call out php functions from within your HTML file? 

If your HTML file (with .htm or .html extension) calls out PHP, it may not work unless in your control panel you have set to parse .htm and/or .html extensions with PHP application. 

Subsequently, you may just name your HTML file with a .php extension so you can just use: 

include 'whatever.php';
shout(); 

to call out your PHP code. 

I hope this helps,
Steven

[Reply] [Back to Top]

.

by hobbit on Thu 09/14/2006 06:07 AM

Hey!
Thank you for your answer :) 

I think I have found a solution, the answer is "template" =D I think with that I can do what I want :)
If you're interested in it, look at "smarty" :) 

[Reply] [Back to Top]

smarty

by uclaboyz on Thu 09/14/2006 12:34 PM

ahh... I see what you are doing.  Yes, smarty is a good system to use, although I find it a bit complicated when I tried it.  I use a simpler template system out of a PHP book. 

Good luck!

[Reply] [Back to Top]

© Copyright 2006-2007.  All Rights Reserved. Site hosted by Small Business Web Design
how to start a blog | parenting tips website | Passive Income | baby websites