LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-28-2009, 09:31 AM   #1
Izarf
LQ Newbie
 
Registered: Nov 2006
Posts: 16

Rep: Reputation: 0
Question gentoo - php in html files?


Is it possible to somehow have php code in .html-files?

If I rename the index.html to index.php or index.phtml, it says syntax error, where there is html code, since it expects php code.

if I rename it back to index.html, I cannot get the php code running. I find this weird! how do I mix php and html while having html as default language?


index.html
Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<?php phpinfo(); ?>
 
Old 05-28-2009, 10:10 AM   #2
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
Could you please post the exact error you see in your browser when you try to rename "index.html" to "index.php"?

You should not be getting an error if you have PHP and HTML in the same PHP file; I do it all the time as I would rather break from a <?php ... ?> section than stay in it and use a whole whack of "echo()"s.

Example:
Code:
<html>
<title>Page title</title>
<head> Something...</head>
<body>
   <?php
      for ($i = 0; $i < 100; ++$i) { echo("$i "); }
   ?>
</body>
</html>
It could be your HTTP server isn't configured properly. When there are nice tools available, I will use Apache, otherwise it is lighttpd all the way; it is much easier to get up and running, and tweak.

EDIT: Okay, when I tested your index.html file (as index.php) it didn't run, but I didn't get an error. I finally got it to work when I removed the "<?xml ... ?>" section.

Last edited by indienick; 05-28-2009 at 10:13 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Merge Of Html Files Into A Single Html (or Pdf) fiomba Linux - Software 10 05-11-2018 11:28 AM
Gentoo Linux - how to map Apache server to look at php files in multiple locations bg108 Linux - Newbie 3 02-07-2008 04:51 AM
Apache rending php when filename is x.php.html mastahnke Linux - Server 6 01-22-2007 08:39 AM
converting a doc/ppt Windows files in html files under linux env agrosu Programming 7 02-23-2006 03:07 PM
html code and including html files Hockeyfan Programming 2 08-22-2005 05:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 11:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration