PHP - Breadcrumb With Php
Similar TutorialsHi, In my application I have not used any folders to define the hierarchy. All file s are in a single folder. What is the easy way of creating the Breadcrumb. I am rewriting the URL from www.mysite.com/main.php/page=pagename&id=10 to www.mysite.com/main/pagename/id/10 Is it possible to use the re-written URL to create the breadcrumb? If yes I can define hierarchy in the URL and use the same to create breadcrumb. This script works fine except, the a href only displays baseurl/current_folder instead of baseurl/other_folder/other_folder/current_folder I'm sure it's simple, but I can't figure it out. Code: [Select] function breadcrumbs($separator = '', $home = 'Home') { $path = array_filter(explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))); $base_url = ($_SERVER['HTTPS'] ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/'; $breadcrumbs = array("<p><a href=\"$base_url\">$home</a></p>"); $last = end(array_keys($path)); foreach ($path AS $x => $crumb) { $title = ucwords(str_replace(array('.php', '_'), Array('', ' '), $crumb)); $title = ucwords(str_replace(array('.html', '_'), Array('', ' '), $crumb)); if ($x != $last){ $breadcrumbs[] = "<p><a href=\"$base_url$crumb\">$title</a></p>"; }else{ $breadcrumbs[] = "<p>$title</p>"; } } return implode($separator, $breadcrumbs); } echo breadcrumbs(); I have a breadcrumb scrpt that works well except I want it to be like the breadcrumb script here on phpfreaks. I need to get parts of the url that the script gets to create the trail and query the database to replace those parts of the url. Say i have a url like mydomain.com/forum/1/2, where 1 is the board and 2 topic, how would i change the code so if the part[1] was forum it replaces parts 2 and 3 with what it's in the database? Here is my breadcrumb script function breadcrumb( $home = 'Home', // Name of root link $division = ' / ', // Divider between links $hidextra = true, // Toggle hide/show get data and fragment in text $index = false, // Toggle show/hide link to directory if it does not contain a file $indexname = 'index.php' // The definition of the file the directory must contain ) { $breadcrumb=""; // Requested addons... $extension = '.php'; // Extension to cut off the end of the TEXT links $ifIndex = 'index.php'; // Filename of index/default/home files to not display // End requested addons $whole = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; $parts = explode('/', $whole); $parts[0] = 'http://'.$parts[0]; $array = array('-', '%20'); $breadcrumb .= "<a href=\"{$parts[0]}\">{$home}</a>{$division}"; $k = 1; for ($i=1;$i < sizeof($parts);$i++) { $uri = '/'; while ($k <= $i) { $uri .= $parts[$k]; if ($k != (sizeof($parts)-1)) $uri .= '/'; $k++; } if (($index && is_dir($_SERVER['DOCUMENT_ROOT'].$uri) && is_file($_SERVER['DOCUMENT_ROOT'].$uri.$indexname) || !$index || !is_dir($_SERVER['DOCUMENT_ROOT'].$uri)) && $parts[$i] != $ifIndex) { $breadcrumb .= "<a href=\"$uri\">"; if ($hidextra) { $breadcrumb .= rtrim(preg_replace("/\?.*$/", '', ucwords(str_replace($array," ",$parts[$i]))), $extension); } else { $breadcrumb .= rtrim(ucwords($parts[$i]), $extension); } $breadcrumb .= '</a>'; } else { $breadcrumb .= ucwords(str_replace($array," ",$parts[$i])); } if (isset($parts[($i+1)])) { $breadcrumb .= $division; } $k = 1; } return $breadcrumb; } |