barrycorrigan Posted June 20, 2011 Share Posted June 20, 2011 Hi Everyone, I have wrote this small script to display some simple breadcrumbs I was wondering how could I get rid of the .php extenstion. And was also wondering if this is the correct way of doing things. I'm new to php so any advice would be great: Here is the code <?php $pagetitle = basename($_SERVER['SCRIPT_NAME']);; $ul_id='breadcrumbs'; echo '<ul id="'.$ul_id.'"><li class="first"><a href="/">Home</a></li>'; echo '<li><a class="selected" href="'.$pagetitle.'">'.$pagetitle.'</a></li>'; echo '</ul>'; ?> Thanks Barry Quote Link to comment https://forums.phpfreaks.com/topic/239904-breadcrumbs-help/ Share on other sites More sharing options...
AMcHarg Posted June 20, 2011 Share Posted June 20, 2011 Just use a string replace on the $pagetitle, replacing ".php" with "". Assuming you never have ".php" written into the $pagetitle, this will always work. Quote Link to comment https://forums.phpfreaks.com/topic/239904-breadcrumbs-help/#findComment-1232313 Share on other sites More sharing options...
redixx Posted June 20, 2011 Share Posted June 20, 2011 $pagetitle = rtrim(basename($_SERVER['SCRIPT_NAME']), '.php'); Quote Link to comment https://forums.phpfreaks.com/topic/239904-breadcrumbs-help/#findComment-1232321 Share on other sites More sharing options...
Adam Posted June 20, 2011 Share Posted June 20, 2011 Using the SCRIPT_NAME as your title is certainly not the way to do it. Plus your code is very static/restricted, despite pulling in the title dynamically. It will only ever work for "Home > thispage" - and the page name as mentioned, if based off of the script name, wouldn't look very good (and possibly not even make sense to the user). It's hard to say how this should be done really, as we know nothing about the navigation structure of your site. When using content from a database it's generally the case to dynamically generate them, but in other cases you may need to set them up yourself. Either way you should only set the breadcrumbs at the highest level within each controller/page's PHP code, and have centralized logic that would handle everything else. If you post more information we can help you further. Quote Link to comment https://forums.phpfreaks.com/topic/239904-breadcrumbs-help/#findComment-1232332 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.