SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2002
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A little PHP trick...

    Anyone know how I can play with this? I have a navigation where each page on the site has a different "header" image, however, the header.gif (header1, header2, header3, etc) are stated in the header.php navigation file. Therefore, each page can only use header1.gif :-(

    Anyway, the question is this. How can I use a little code of PHP to get the name of the page minus the PHP extension (i.e. contactus.php = contactus) and add the letters ".gif" after it. This way, I can link to different header files even though the HTML for the header image is embeded into the header.php file of my site.

    I hope this makes sense.

  2. #2
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    PHP Code:
    $new_file mixed str_replace (".php"".gif"$old_file
    My name is Steve, and I'm a super-villian.

  3. #3
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lieut_data
    Try this:
    PHP Code:
    $new_file mixed str_replace (".php"".gif"$old_file
    An easier approach (since in your approach, you would need to get just the filename of the script first for use in $old_file, for which you need basename() ):
    PHP Code:
    $headerimage=basename($_SERVER['PHP_SELF'],'.php'); 

  4. #4
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Icheb
    PHP Code:
    $headerimage=basename($_SERVER['PHP_SELF'],'.php'); 
    Nice!

    Just append ".gif", and we have a single line solution :-)
    My name is Steve, and I'm a super-villian.

  5. #5
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $headerimage=basename($_SERVER['PHP_SELF'],'.php') .'.gif'
    There.


Bookmarks

Posting Permissions

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