How do you Parse PHP with HTML file extensions?
-
Spent two whole days on one line of code to get a simple PHP comment script working and still no joy. I don't understand PHP but am good at following step by step instructions word for word! I have been told that if I add this line of code below to the .htaccess file it will enable me to insert PHP into html... Well the PHP I have inserted shows nothing. So i take it that this is the root cause of the problem... I have cycled through: AddType application/x-httpd-php .php .html .htm AddHandler application/x-httpd-php .php .html .htm AddType x-mapp-php4 .html .htm AddType x-mapp-php4 .html .htm Error log looks like this: [30-Jan-2013 12:20:44] PHP Notice: Undefined index: identifier_list in /vhost/vhost8/s/t/o/http://ssdfsdfdsdf.com/www/comments/cache/%%74%5E748%5E74858DDB%%admin_identifier_list.tpl.html.php on line 116
-
Answer:
PHP is working if you got that error. Your problem is in your PHP code - could you post the code sample or full error log? In fact that the problem is on line 116 of the file listed there.
Nicholas Pickering at Quora Visit the source
Other answers
You write the file as a .php file - most web servers can't be forced to parse and run PHP from an .htm file. In that file, close the PHP part with ?> then add your HTML code, or use echo statements in PHP to echo the HTML to the client. Example: <?php #this is an example of PHP code $variable = 5 + $other_variable; ?> <! HTML code starts here > Or: <?php #this is an example of PHP code $variable = 5 + $other_variable; echo 'This is going to show up on the screen, because it\'s text as far as HTML is concerned.' echo '<br />'; echo 'This is another line.'; ?> You can include Javascript in echo statements, since they're just sent to the browser as-is. If you want to include data from the server, you can echo an HTML line with server data included in it, or jump out of PHP (?>), out in the HTML, jump back and put in the variable (that's how WpordPress does things, and it's not really good practice). But getting the server to parse php that's in a file with an .htm or .html extension? Don't do that. (Change an htm file to have a php extension and it'll still work. The server will just output the html text until it encounters the initial <?php - which it never will, and it won't care.)
Al Klein
Related Q & A:
- How do I parse nested JSON object?Best solution by Stack Overflow
- How to use external PHP file in СakePHP 2?Best solution by Stack Overflow
- How can I parse a complex XML with PHP and CDATA?Best solution by Stack Overflow
- How to convert a HTML file to XML file?Best solution by Stack Overflow
- How long do real human hair clip-in extensions last?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.