Online Shopping : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to
Did You Find This Entry Useful?

45 of 66 people (68%) answered Yes
Recently 7 of 10 people (70%) answered Yes


Can I embed a PHP file in an HTML file. Similar to the <script src="abc.js"></script> for Javascript

Apr 2nd, 2009 06:24
engatoo engatoo, osososo didididi, Taksh Verdhan, healthy man, dman, forum net tr, yrt e, Christopher Bachmann,

PHP is a server side scripting language and PHP scripts need to be
executed on the server to be of any use to you.  Javascript is a client
side (browser) language and does not require the server to parse the
file before it is sent to the browser.
You can do this with "exec cgi" in sHTML files, but the problems with
this are described at:
You can, however, use PHP to generate code which you use in a client
side script tag.  Add the following to your html file:
<script src=""></script>
Then make a PHP script on your server (must have PHP installed):
<?  print "alert('hey !');\n"; ?>
and then load the HTML file, you should see the alert box.  You have
just used PHP to generate text for a client-side include.
There is apparently a way to do this in Mozilla 1 / Netscape 7 using 
<object> tag which is described at:
This seems to sort of do what you want it to, the syntax for this 
would be:
<object type="text/html" data=""></object>
Which I found does work in Mozilla 1 (rc2).
The other workaround is to use frames.
However, what you are probably asking is if you can use PHP like an
shtml include where anything the PHP script generates is assembled
inline with any HTML you have around it.  The answer is "not really".
Basic HTML does not have any standard for handling includes.  This is a
limitation with the HTML 4.0 spec and has little to do with PHP.