Embedding PHP Code in HTML Files
Query:
Incorporating PHP code into HTML (extension .html) proves challenging. Attempts to utilize both " contents ?>" and "" yield no success. Despite PHP availability on the server and its functionality when using the .php extension, this issue persists. Is it an inherent limitation or a matter of configuration in php.ini?
Response:
The inability to execute PHP within .html files stems from the server's lack of recognition of said extension as a valid PHP container. To rectify this, a .htaccess file must be created in the web directory's root. By appending the following line to the file:
AddType application/x-httpd-php .htm .html
Apache will be instructed to process files with .htm or .html extensions as PHP scripts. This allows PHP to be embedded in HTML files effortlessly.
The above is the detailed content of Can I Embed PHP Code in HTML Files (`.html` extension)?. For more information, please follow other related articles on the PHP Chinese website!