Solved

PHP Includes syntax

Posted on 2003-11-24
7
389 Views
Last Modified: 2013-11-18
Hi

I have no previous php experience and have the following problem:

I have a site hosted with php access.  I want to do the equivalent of a SSI but with php syntax.

My provider is not being forthcoming with turning on SSI's in the environment and are suggesting using php to include the file.

Basically my question is from within an html document how do i include another snippet of html (My navigation) into the file using php to call it?

Basically i want to do this in php:

<!--#include file="file:includeFile.htm" -->

Thanks in advance

Blue52
0
Comment
Question by:Blue52
  • 3
  • 3
7 Comments
 
LVL 13

Expert Comment

by:lozloz
ID: 9809915
<? include("includeFile.htm"); ?>

loz
0
 

Author Comment

by:Blue52
ID: 9809948
is that <? space include("includeFile.htm");  space ?>   ?

I will try it shortly and award accordingly.

Thanks for being swift

Blue52
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9809980
doesn't matter, any amount of spaces will work (including none), a space on either side is good syntax i'd say

loz
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:ThG
ID: 9810000
lozloz, using the extended tag is highly encouraged.

<?php  include("includeFile.htm"); ?>
0
 

Author Comment

by:Blue52
ID: 9810610
So to use php includes do i need to rename the calling file template.htm to template.php.  I ask because I have tried what you have suggested and it doesn't work.  However, i have renamed the the calling file and the called file to .php and now i get this:

Parse error: parse error in /usr/home/momo55/public_html/template.php on line 1

So this suggests to me that either i cannot use a php include in a standard .htm file or i if i rename my calling file to .php i need to add something to the file to make it work as a .php file.

The code i am using embedded in the calling .html file is this:

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Tiger Woods Online</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="css/default.css" rel="stylesheet" type="text/css" />
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<table width="760" border="0" cellspacing="0" cellpadding="0">
      <tr valign="top">
            <td width="8"><img src="images/shim.gif" width="8" height="300" /></td>
            <td width="132" background="images/navBG.jpg">
            <?php  include("include_nav.htm"); ?>
            </td>
            <td width="22"><img src="images/shim.gif" width="22" height="300" /></td>
          <td class="copy">copy</td>
      </tr>
</table>

</body>


So do i need to:

Call my calling file .php and if so do i need to add anything to the page to make it work?

or

Do i need to do anything else if i leave it as a .html file and if so what.

Thanks again

Blue
</html>

0
 
LVL 13

Accepted Solution

by:
lozloz earned 100 total points
ID: 9810652
<?xml version="1.0" encoding="iso-8859-1"?>

this is your problem as it thinks that <? is the start of a section of php code. luckily i was reading about this earlier today:

http://uk.php.net/manual/en/faq.using.php#faq.using.mixml

so basically you want to change the first line there to be:

<?php print "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n"; ?>

cheers,

loz
0
 

Author Comment

by:Blue52
ID: 9811485
A great help

Many thanks

Andrew
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question