php include

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • philleep
    New Member
    • Mar 2007
    • 74

    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...
    [code=html]
    <div id="menu">

    <?= file "menu.html" ?>

    </div> <!--End of menu-->

    my include file:

    <ul>
    <li><a href="index.htm l">Home</a></li>
    <li><a href="contact.h tml">Contact Us</a></li>
    <li><a href="radlok.ht ml">Radlok Cart Retention</a></li>
    <li><a href="sos.html" >SOS Product Security Alarm</a></li>
    <li><a href="eatmecrun chy.html">Eatme crunchy Cereal Bowl </a></li>
    <li><a href="paving.ht ml">Paving with a Message</a></li>
    <li><a href="timing.ht ml">Timing<br />Old Inventions</a></li>
    <li><a href="bio.html" >Gray Matter Biography</a></li>
    </ul>[/code]

    [Please use CODE tags when posting source code. Thanks! --pbmods]

    cheer,
    philleep
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    Try using include_once.

    Comment

    • nathj
      Recognized Expert Contributor
      • May 2007
      • 937

      #3
      Originally posted by philleep
      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...
      [code=html]
      <div id="menu">

      <?= file "menu.html" ?>

      </div> <!--End of menu-->

      my include file:

      <ul>
      <li><a href="index.htm l">Home</a></li>
      <li><a href="contact.h tml">Contact Us</a></li>
      <li><a href="radlok.ht ml">Radlok Cart Retention</a></li>
      <li><a href="sos.html" >SOS Product Security Alarm</a></li>
      <li><a href="eatmecrun chy.html">Eatme crunchy Cereal Bowl </a></li>
      <li><a href="paving.ht ml">Paving with a Message</a></li>
      <li><a href="timing.ht ml">Timing<br />Old Inventions</a></li>
      <li><a href="bio.html" >Gray Matter Biography</a></li>
      </ul>[/code]

      [Please use CODE tags when posting source code. Thanks! --pbmods]

      cheer,
      philleep
      Or you could try

      [CODE=php]
      <?php include("folder/file.ext"); ?>
      [/CODE]
      or
      [CODE=html]
      <!--#include file="folder/file.ext" -->
      [/CODE]
      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

      Comment

      • tscott
        New Member
        • Jul 2007
        • 22

        #4
        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

        Comment

        • nathj
          Recognized Expert Contributor
          • May 2007
          • 937

          #5
          Originally posted by tscott
          [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

          Comment

          Working...