Solved

PHP Includes syntax

Posted on 2003-11-24
7
369 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

705 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

20 Experts available now in Live!

Get 1:1 Help Now