Solved

PHP Includes syntax

Posted on 2003-11-24
7
375 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
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.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

910 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now