I'm trying to sort out a way I can load an image based on a url. For instance, if my php is being called from http://www.domain.com/news/ it should load subheader_news.jpg. If it's being loaded from http://www.domain.com/weather/ then it should load subheader_weather.jpg and so on. An issue is that sometimes the url will be longer than that, so in the first example it might be http://www.domain.com/news/articles/daily/today.php yet I'll still need it to load subheader_news.jpg. In other words I need to load an image based on the first directory name after the root URL, whether it's /news/, /weather/ or whatever else.
Any thoughts as to how to pull that piece of the URL out on page load, and then insert it into the img code to load the proper image for that location? Sort of like
- If it resides in http://www.domain.com/news/articles/
Get url and strip out everything except /news/
Insert /news/ (minus slashes) into image code such as img src=http://domain.com/images/subheader_news.jpg
Any help would be appreciated.