Jump to content
Larry Ullman's Book Forums
koalajiang

Question For Script 12.7 How Can Html File Execute Php Code?

Recommended Posts

Hi:

 

I was reading chapter 12, and found script 12.7 line 19 embed with php code? i am wondering how a html file can execute this php code? Should you change the header.html to header.php?

Share this post


Link to post
Share on other sites

Good question! The header.html is being included by PHP, so it's as if the header.html code is part of the original PHP script. It could have literally any extension and still work. 

Share this post


Link to post
Share on other sites

Hi Larry:

 

You mentioned that The header.html is being included by PHP. Do you mean in the index.php file --

 

<?php #  index.php

$page_title = 'xxxxx';
include ('./includes/header.html');
?>
 
so that header.html code is part of the original php script?? If so why when i type php code in header.html file with netbeans, there is no code hint, and also the php code color is light blue?

Share this post


Link to post
Share on other sites

Also remember that PHP is an interpreted language. That means that PHP code is executed by a interpreter, not from a compiled source. The file extension .php has no special functionality. The interpreter might also run .html, .txt or .randomExtension as PHP if you can just tell PHP and Apache to treat it that way.

 

This article might clear some things up:

http://php.about.com/od/advancedphp/p/html_php.htm

Share this post


Link to post
Share on other sites

Netbeans probably only uses the file's extension to know how to behave. It doesn't understand the greater context. If that's a problem, use .php for the header file extension.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...