Hello, I'm kind of new to PHP and I was wondering if anyone would know how to display a particular image depending on what section of the website you are in. example: (something.com/the-band) or (something.com/the-band/something) the photo would be "the-band.jpg" but if you were in (something.com/music) or (something.com/music/something) the photo would be "music.jpg" If anyone could shed some light, it would be much appreciated. Cheers, Ross
Would this be for anything, for example something.com/abc would search for abc.jpg even if it wasn't existant, or only for a few set things, IE your directories?
It would be something like: if url = the-band or the-band/something then <img src="someimage.jpg" /> else if url = music or music/something then <img src="someotherimage.jpg" /> I just don't know how to code it.
Sorry I was wrong. It took 4 lines. <?php $graburl = $_SERVER['REQUEST_URI']; $searchstring = strpos($graburl,'x'); // x is what you want php to find in the url If ($searchstring === false) {echo "http://www.yourdomain.com/someimage.jpg";} // Type which image to display if php can't find it. else {echo "http://www.yourdomain.com/someimage.jpg";} // Type which image to display if php finds it. ?> PHP: You can pay me back in good reputation. But, my site likes links too. P.S. You would place this where you would type the normal <img src="abovephpcode">
Awesome, thanks a bunch. That worked with some tweaking. Here is my final code: $graburl = $_SERVER['REQUEST_URI']; if ($searchstring = strpos($graburl,'home')) { $photocolumn = "photocolumn_bg_home.jpg"; } else if ($searchstring = strpos($graburl,'the-band')) { $photocolumn = "photocolumn_bg_theband'.jpg"; } else if ($searchstring = strpos($graburl,'music')) { $photocolumn = "photocolumn_bg_music.jpg"; } else if ($searchstring = strpos($graburl,'blog')) { $photocolumn = "photocolumn_bg_blog.jpg"; } else if ($searchstring = strpos($graburl,'events')) { $photocolumn = "photocolumn_bg_ events.jpg"; } else if ($searchstring = strpos($graburl,'contact-us')) { $photocolumn = "photocolumn_bg_contactus.jpg"; } else if ($searchstring = strpos($graburl,'user')) { $photocolumn = "photocolumn_bg_user.jpg"; } else $photocolumn = "photocolumn_bg_home.jpg"; Code (markup):
I doubt the switch command will speed anything up for you. You barely have that many cases. Once you get your code above 200 lines of else if statements than worry about it.