sibrows Posted November 10, 2008 Share Posted November 10, 2008 Hi All I've been playing with a bit of OOP I am trying to write a function to build a breadcrumbs navigation built from the contents of the URL. So far I have this: Call the function: BreadCrumbs($_SERVER['REQUEST_URI']); The function code: function BreadCrumbs($URL){ $URL_PATH = explode("/", $URL); $URL_PATHcount = count_all($URL_PATH); $Count = 1; $SubCount = 1; echo '<div class="BreadCrumbs"><a href="/"><img src="/icons/home.png"></a>'; do { echo ' > <a href="'; do { echo '/'. $URL_PATH[$SubCount]; $SubCount = $SubCount + 1; } while ($SubCount <= $Count); echo'">' . $URL_PATH[$Count] . '</a>'; $Count= $Count + 1; } while ($Count <= $URL_PATHcount); echo '</div>'; } Currently if the URL is: http://localhost/Section/SubSection/Page The Output (ignoring the home icon): > Section > SubSection > Page The issue I have is when trying to build the links for each page. Currently it is pointing to: Section = 'http://localhost/Section' SubSection = 'http://localhost/SubSection' Page = 'http://localhost/Page' I'm now a little stuck with what to try next having spent most of the weekend trying to get it sorted. Any help would be gratefully received. Simon Quote Link to comment Share on other sites More sharing options...
rhodesa Posted November 10, 2008 Share Posted November 10, 2008 here is a cleaner version <?php function BreadCrumbs($url){ $parts = explode('/',$url); unset($parts[0]); $path = ''; echo '<div class="BreadCrumbs"><a href="/"><img src="/icons/home.png" /></a>'; foreach($parts as $part){ $path .= '/'.$part; printf(' > <a href="%s">%s</a>',$path,$part); } echo '</div>'; } BreadCrumbs('/Section/SubSection/Page'); ?> Quote Link to comment Share on other sites More sharing options...
sibrows Posted November 11, 2008 Author Share Posted November 11, 2008 Great thanks worked like a charm. Quote Link to comment 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.