Embedding PHP code/file in HTML file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dagadakrishna
Forum Commoner
Posts: 29
Joined: Fri Jan 19, 2007 3:30 am

Embedding PHP code/file in HTML file

Post by dagadakrishna »

hi can anyone help me how to embedd PHP file/code in HTML file

suppose i have HTML file Like this

<html>
<head></head>
<body>
WELCOME
</body>
</html>

here suppose if i want to put PHP code how to do.

I have written like this in my "Welcome.html"

<html>
<head></head>
<body>

WELCOME
<h1>
<?php echo "I LOVE PHP!"; ?>
</h1>

</body>
</html>

But its not working.

is it the correct way of writing

And another one is if i want to include PHP file in my HTML file means whats the procedure, can any one suggest me

Byeeeeeeee
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Post by matthijs »

Code: Select all

<html>
<head></head>
<body>

WELCOME
<h1>
<?php echo "I LOVE PHP!"; ?>
</h1>

</body>
</html>
Did you save the page as welcome.php? The extension is important.

Your code is ok.
dagadakrishna
Forum Commoner
Posts: 29
Joined: Fri Jan 19, 2007 3:30 am

Post by dagadakrishna »

Means with .html extension is it not possible?

.php extension means it will become PHP file na,i want it in HTML file only is it not possible?
User avatar
Dr Evil
Forum Contributor
Posts: 184
Joined: Wed Jan 14, 2004 9:56 am
Location: Switzerland

Post by Dr Evil »

It has to be *.php as this tells the server what the file contains and makes the server parse it.

A *.php file can contain only html if you wish.

Make sure you have a server running on your testing machine too, or you want get proper output.

(you could configure your server to parse *.html too, but I strongly sugest you don't).
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

If you are at all set on using html files however, you would put your php code into separate *.php files and then include them into your html

Code: Select all

<!--#include file="*.php"-->
dagadakrishna
Forum Commoner
Posts: 29
Joined: Fri Jan 19, 2007 3:30 am

Post by dagadakrishna »

hi u gave me a suggestion of placing <!--#include file="*.php"--> this iin HTML code ,but where to put this code
i tried like this its not working

my Welcome.html file

<html>
<head>
#include file="data.php"

<title>PHP Test</title>
</head>
<body>
</body>
</html>


Where to put that line
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

firstly, the <!-- --> is part of the syntax

Secondly, you can put it whereever. If it outputs anything you probably want it in the body. Otherwise, who cares where you put it? :-p
gavin1996
Forum Newbie
Posts: 22
Joined: Tue Jan 30, 2007 8:30 pm

Post by gavin1996 »

Guy,you should using javascript or iframe


<script src="../temp.php"></script>


<iframe src=''></iframe>
dagadakrishna
Forum Commoner
Posts: 29
Joined: Fri Jan 19, 2007 3:30 am

Post by dagadakrishna »

ya what u told is correct its working fine

Thanks for ur help
dagadakrishna
Forum Commoner
Posts: 29
Joined: Fri Jan 19, 2007 3:30 am

Post by dagadakrishna »

if u put <!--#include file="text_file_hit_counter.php"--> like this then it will become comment na how it will become sytax
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

LAST WARNING before punishment is handed out dagadakrishna.
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.

Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.
Post Reply