faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

44 of 65 people (68%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

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

Dec 10th, 2008 09:33
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:
http://www.faqts.com/knowledge_base/view.phtml/aid/4138/fid/2
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="http://url.org/script.php"></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 
the
<object> tag which is described at:
 http://www.w3.org/TR/REC-html40/struct/objects.html#h-13.3
This seems to sort of do what you want it to, the syntax for this 
would be:
<object type="text/html" data="http://url.org/script.php"></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.
http://www.aspiringphotography.info
http://www.anandenterprises.info/
http://www.southsunhomes.com/
http://bankruptcyknowledge.info
http://www.cosmiccobra.com
http://www.menorcahotel.info/
http://www.impact-post.com/
http://www.tricksdump.com/
http://www.projectsupervisors.com/