www.webdeveloper.com
Results 1 to 3 of 3

Thread: Cross file variables

Hybrid View

  1. #1
    Join Date
    Feb 2012
    Posts
    4

    Unhappy Cross file variables

    I want the content on a page of my website to appear on two different pages. At the moment i have copied and pasted the content into the code of the files but this means that if i want to edit the content then i have to do it twice, it also means that i am taking up twice as much space. I tried to put the content into a PHP variable then just echo the variable on the second page but that doesnt work. Is there a way to have a cross file variable so i only have to put the content on one page then just put a variable on the other?

    Thanks,
    Louis

    P.S: please bear in mind I am relatively new to PHP so when writing answers keep this is mind

  2. #2
    Join Date
    Dec 2005
    Posts
    2,984
    I think what you want is to use a php include. It allows you to have a common part of your site (e.g. like the nav, or the footer) in a separate file and you can just 'include' it into all of your other files. I may have misinterpreted what you meant, sorry if I have.

    HTML Code:
    <!-- nav.php -->
    <ul>
      <li><a href="#">Some Link</a></li>
       ....
      <li><a href="#">Some Link</a></li>
    </ul>
    PHP Code:
    //index.php
    <html>
     <head>
     </head>
     <body>
        <?php include('nav.php'); ?>
     </body>
    </html>
    PHP Code:
    //sub-page.php
    <html>
     <head>
     </head>
     <body>
        <?php include('nav.php'); ?>
     </body>
    </html>
    I've switched careers...
    I'm NO LONGER a scientist,
    but now a web developer...
    awesome.

  3. #3
    Join Date
    Feb 2012
    Posts
    4
    Yes thank you! That helps me so much!!! I shouldve turned to forums a long time ago, instead of spending hours googling! Thank you once again!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles