Jump to content



Photo

Saving Files As Php Or Html


  • Please log in to reply
2 replies to this topic

#1 Paul

Paul

    Advanced Member

  • Members
  • PipPipPip
  • 143 posts
  • LocationCumbria, UK

Posted 8 March 2012 - 4:37 AM

Hi all,
I have created a file in Dreamweaver that is going to be a header include, as follows:

<?php
// Di's Soft Furnishings
// header.html
// The header file
ob_start();
session_start();
if (!isset($page_title))
{
$page_title = 'Di\'s soft Furnishings';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $page_title; ?></title>
</head>
<body>
<?php
echo '<p>hello</p>';
?>
</body>
</html>


I saved it as header.html and run it through local host (XAMPP). It displayed the ';?> after the hello. I then save the same code as header.php and run it through local host and it was perfect.

Question: Does it matter if I save a file as html or php? I also understood that php could be placed within html OK. It doesn't seem to be the case here.

Thanks for any help.
Paul
  • 0

#2 Paul Swanson

Paul Swanson

    Excellent Advisor

  • Members
  • PipPipPip
  • 163 posts
  • LocationPortland, OR, USA

Posted 8 March 2012 - 1:55 PM

If your header.html file were included in another .php file, it would work okay. But on it's own, the server wouldn't run it through the PHP interpreter because it doesn't have a .php extension. The server uses the extension to determine whether it needs to send it through the interpreter. So, if you had an index.php with include 'header.html'; it should work fine because the index.php file will be run through the PHP interpreter, along with any files it includes.
  • 0

#3 Paul

Paul

    Advanced Member

  • Members
  • PipPipPip
  • 143 posts
  • LocationCumbria, UK

Posted 9 March 2012 - 7:43 AM

Paul,
That makes sense. Thanks for your help.

Paul
  • 0