Solved

PHP Includes syntax

Posted on 2003-11-24
7
392 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

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!

Question has a verified solution.

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

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…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

739 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