473,394 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

php include

Hi,

i've just started on php. i want to split my site up into include files so that i can have seperate html files with my menu etc in and then include them in the php page. the code i've been using is below - when i do this i get the desired effect except there server puts a '1' in the webpage under the included part. Any ideas?

My code:

from my php file...
Expand|Select|Wrap|Line Numbers
  1. <div id="menu">
  2.  
  3. <?= file "menu.html" ?>
  4.  
  5. </div> <!--End of menu-->
  6.  
  7. my include file:
  8.  
  9.   <ul>
  10.         <li><a href="index.html">Home</a></li>
  11.     <li><a href="contact.html">Contact Us</a></li>
  12.     <li><a href="radlok.html">Radlok Cart Retention</a></li>
  13.     <li><a href="sos.html">SOS Product Security Alarm</a></li>
  14.     <li><a href="eatmecrunchy.html">Eatmecrunchy Cereal Bowl </a></li>
  15.     <li><a href="paving.html">Paving with a Message</a></li>
  16.     <li><a href="timing.html">Timing<br />Old Inventions</a></li>
  17.     <li><a href="bio.html">Gray Matter Biography</a></li>
  18.   </ul>
[Please use CODE tags when posting source code. Thanks! --pbmods]

cheer,
philleep
Jul 19 '07 #1
4 1335
mwasif
802 Expert 512MB
Try using include_once.
Jul 19 '07 #2
nathj
938 Expert 512MB
Hi,

i've just started on php. i want to split my site up into include files so that i can have seperate html files with my menu etc in and then include them in the php page. the code i've been using is below - when i do this i get the desired effect except there server puts a '1' in the webpage under the included part. Any ideas?

My code:

from my php file...
Expand|Select|Wrap|Line Numbers
  1. <div id="menu">
  2.  
  3. <?= file "menu.html" ?>
  4.  
  5. </div> <!--End of menu-->
  6.  
  7. my include file:
  8.  
  9.   <ul>
  10.         <li><a href="index.html">Home</a></li>
  11.     <li><a href="contact.html">Contact Us</a></li>
  12.     <li><a href="radlok.html">Radlok Cart Retention</a></li>
  13.     <li><a href="sos.html">SOS Product Security Alarm</a></li>
  14.     <li><a href="eatmecrunchy.html">Eatmecrunchy Cereal Bowl </a></li>
  15.     <li><a href="paving.html">Paving with a Message</a></li>
  16.     <li><a href="timing.html">Timing<br />Old Inventions</a></li>
  17.     <li><a href="bio.html">Gray Matter Biography</a></li>
  18.   </ul>
[Please use CODE tags when posting source code. Thanks! --pbmods]

cheer,
philleep
Or you could try

Expand|Select|Wrap|Line Numbers
  1. <?php include("folder/file.ext"); ?>
  2.  
or
Expand|Select|Wrap|Line Numbers
  1. <!--#include file="folder/file.ext" -->
  2.  
Note: thefile that has this second option in must be *.shtml so that the server knows to get the include fle or it can be *.php I believe.

Cheers
nathj
Jul 19 '07 #3
tscott
22
I know of an easier way that would help you in the long run.
Divide your code with a | in the places you would make each page with.
Then set it as a variable in your file, using explode each section is split apart from each other setting each as it's own ID the first portion would be $filearray[0] , 2nd, $filearray[1] etc...

[php]
<?php
$file = '<html>| Random Text | pie | </html>';
$filearray = explode('|' , $file);
echo filearray[2];
?>
[/php]

That would make it easier right? :)

~Tyler
Jul 19 '07 #4
nathj
938 Expert 512MB
[php]
<?php
$file = '<html>| Random Text | pie | </html>';
$filearray = explode('|' , $file);
echo filearray[2];
?>
[/php]
Tyler,

I'm intrigued by this approach to including external files. Are you outlining an alternative to the use of the PHP include() function?

I'm not sure I see the benefit of this approach over INCLUDE or even the SSI (<!--#include...)? What advantage does this methodology offer?

Cheers
nathj
Jul 20 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

43
by: steve | last post by:
I am quite frustrated with php’s include, as I have spent a ton of time on it already... anyone can tell me why it was designed like this (or something I don’t get)? The path in include is...
0
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug...
60
by: Derrick Coetzee | last post by:
It seems like, in every C source file I've ever seen, there has been a very definite include order, as follows: - include system headers - include application headers - include the header...
9
by: zolli | last post by:
Hi, I've been banging my head against this for a while now. Hoping someone here can shed some light on what's going on. On including stdlib.h in a file, I'm seeing the following errors: ...
5
by: David Mathog | last post by:
One thing that can make porting C code from one platform to another miserable is #include. In particular, the need to either place the path to an included file within the #include statement or to...
1
by: Minh | last post by:
I've just installed VS.NET 2003 on my Athlon XP 1800+. However I couldn't get any project with STL includes to compile even if I create a new empty project (and added #include <string>). It gave me...
1
by: ya man | last post by:
when i use #include <iostream.h> in some files i get lots of error messages of the kind 'ambiguous symbol this is solved when i use #include <iostream why is that ? and can i use #include...
3
by: Arpi Jakab | last post by:
I have a main project that depends on projects A and B. The main project's additional include directories list is: ...\ProjectA\Dist\Include ...\ProjectB\Dist\Include Each of the include...
14
by: Jon Rea | last post by:
I am currently cleaning up an application which was origainlly hashed together with speed of coding in mind and therefore contains quite a few "hacky" shortcuts. As part of this "revamping"...
7
by: Giancarlo Bassi | last post by:
Please, what are here the 11 include files (found over the internet)? */mozzarella.c /* #include #include #include #include #include #include
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.