Can we include php file in html file?
How can we include a php file into a html file?
I know we can do this with:
<AddType application/x-httpd-php .html>
but I don't have acces开发者_如何学JAVAs to the server. Any other solution which I can include in my website folder or file?
Why not just rename the file to end in PHP? That would be the simplest way to do this.
If you have access to your website folder, you could create a .htaccess
file that includes:
<IfModule mod_mime.c>
AddType application/x-httpd-php .php
AddType application/x-httpd-php .html
</IfModule>
You could alternatively try:
<FilesMatch "\.(htm|html|php)$">
SetHandler application/x-httpd-php
</FilesMatch>
Depending on what the code looks like that you want to include, and if you really have no other choice like the ones presented by Druid, you can use one of the following less-than-perfect embedding solutions:
An IFRAME with frameborder="0" pointing to the PHP script (Downside: dynamic resizing according to output size is possible only with JavaScript
An AJAX Snippet that loads the PHP file onLoad and injects the output into a DIV of your choice
A tag pointing to the PHP file. The PHP file must then issue JavaScript commands like "document.write()".
The IFRAME is the most fail-safe in the event the client has no JavaScript. The AJAX Snippet is the most elegant solution.
The correct solution is not renaming it to .php
.
It is renaming to .phtml
;)
.phtml is the official file type for crossover files containing PHP
and HTML
code.
精彩评论