Solved

PHP Includes syntax

Posted on 2003-11-24
7
383 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

839 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