PHP
  Home arrow PHP arrow Page 3 - Dynamic Generation of Menu Structures and JavaScript Rollovers in PHP
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

Dynamic Generation of Menu Structures and JavaScript Rollovers in PHP
By: Chris Mospaw
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 11
    1999-05-10


    Table of Contents:
  • Dynamic Generation of Menu Structures and JavaScript Rollovers in PHP
  • Making a Template
  • Starting to Automate
  • The power of repetition
  • Ordering up a Menu
  • Adding Pages

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Dynamic Generation of Menu Structures and JavaScript Rollovers in PHP - Starting to Automate
    ( Page 3 of 6 )

    The first step in automating the generation of these pages is to determine which page is being displayed. PHP comes with great environmental variable support, so determining this information is fairly straightforward.

    I've found that certain environmental variables are not uniformly supported on all implementations of PHP and all servers. Since my local development machine is a Windows 95 box and the Internet server a Unix box, the code that works on both is a bit convoluted. But it works on all installations I've tested it on.

    This code, which should be put at the top of the script, simply puts the name of the current page (with no file type suffix) into the $page variable:

    <? $page=getenv(SCRIPT_NAME) ; $page = split( "/", $page, 4); $page = "." . $page[3]; $page = split( "\.", $page, 3); $page = $page[1]; ?>

    You will probably have to adjust the "4" in line 3, and the "3" in line 4 since they refer to the depth of the directories on your machine, and that's likely to be different than mine. Inserting an echo "$page
    n"; between each line in the above snippet helps to track where things are going while adjusting lines 3 and 4 to work properly in your configuration.

    Now that we have the current page name without any file extensions, we're ready to start having PHP automate some items, such as the header graphic. Replace the "1 - Header Area" text with this line:


    <IMG SRC="<? echo "$page-h.gif"; ?>" WIDTH=596 HEIGHT=50 BORDER=0 ALT=""><BR>

    Notice the "inline" PHP in the SRC attribute, which just echoes the page name followed by the "-h" suffix. The height and width attributes are "hard wired" in, but can be changed at any time if the dimensions of the graphics change.

    Since this site will have more than one page, the script will have to know what the other pages in the site are named. For ease of maintenance, do this in a separate script called PAGES.HTML that is INCLUDEd in the main script. All PAGES.HTML does it to define an array containing the names of all the pages to be dynamically generated.


    <? $site_pages = array("index", "info", "clients", "contact" ); ?>

    There would be 4 pages in the dynamically generated menus on this particular site. Don't forget to insert:


    <? include "pages.html"; ?>

    near the top of the TEMPLATE.HTML script.


     
     
    >>> More PHP Articles          >>> More By Chris Mospaw
     

       

    PHP ARTICLES

    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek