Re: Image script

From: Date: Sun, 13 Apr 2003 13:40:48 +0000
Subject: Re: Image script
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-143663@lists.php.net to get a copy of this message
> From: Lowell Allen <la@lowellallen.com> > >> From: "luther" <lblanton@spacebetween.com> >> >> Is there a script to use with images that will determine which graphic is >> needed by the name of the page? For example, say you have a site which uses >> a unique header graphic for each section but you don't want to hardcode the >> exact name of the image into each HTML page. So, if you have a file called >> "news.php" it would automatically determine the "News" graphic is >> needed for >> that page. >> >> Any help would be appreciated as I've looked and looked and can't find a >> script like this anywhere. > > You can write simple functions that display specific sections of a page > (using different graphics or menus or whatever) based on URL: > > function display_header($page) { > if (ereg("page_name_1", $page) { > $graphic = "this.jpg"; > } elseif (ereg("page_name_2", $page){ > $graphic = "that.jpg"; > } else { > $graphic = "default.jpg"; > } > // HTML code using $graphic > } > > When you call the function, pass it the value of the current page: > > display_header($PHP_SELF); > Sorry -- it works better with correct parentheses: function display_header($page) { if (ereg("page_name_1", $page)) { $graphic = "this.jpg"; } elseif (ereg("page_name_2", $page)) { $graphic = "that.jpg"; } else { $graphic = "default.jpg"; } // HTML code using $graphic } -- Lowell Allen

« previous php.general (#143663) next »