Welcome, guest | Sign In | My Account | Store | Cart

Displays "you are here" (breadcrumbs) information in text, and link form ralative to your path in the following format:

Site > Directory > Sub Directory > Page

It enables a friendly site name, drops the file extension, uses your choice of seperators, and can be changed very easily. This is BSD Licensed.

PHP, 65 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?
/*
Author: Flinn Mueller
Last Updated: 2/26/03
Copyright 2001-2003 ActiveIntra.net, Inc.
Home: http://activeintra.net/php/article.php?id=2
Contact: flinn _AT_ activeintra _DOT_ net
*/
class URHere {
    var $sitename = "My Site";
    var $seperator = "&gt;"; // "&gt;" is ">", "&lt;" is "<", ":", ,"::", "|", "*""
    var $text = "";
    var $link = "";

    function Text($sent_path = "")
    {
        if (strlen($sent_path) > 0)
            $path = explode("/", $sent_path);
        else
            $path = explode("/", $_SERVER[PHP_SELF]);

        $c = 1;
        while (list($key, $val) = each($path)) {
            if ($c > 1) {
                $this->text .= " " . $this->seperator . " ";
                $val = str_replace("_", " ", $val); //Strip underscore
                $val = str_replace("-", " ", $val); //Strip hyphen
                $this->text .= ucwords(ereg_replace("\..*$", "", $val)); //Strip extensions
            } else {
                $this->text = $this->sitename;
            } 
            $c++;
        } 
        return $this->text;
    } 

    function Link($sent_path = "")
    {
        if (strlen($sent_path) > 0)
            $path = explode("/", $sent_path);
        else
            $path = explode("/", $_SERVER[PHP_SELF]);

        $c = 1;
        while (list($key, $val) = each($path)) {
            if ($c > 1) {
                $this->link .= " " . $this->seperator . " ";
                if ($c < count($path))
                    $link .= "$val/";
                else
                    $link .= "$val";
                $val = str_replace("_", " ", $val); //Strip underscore
                $val = str_replace("-", " ", $val); //Strip hyphen
                $this->link .= '<a href="/' . $link . '">' . ucwords(ereg_replace("\..*$", "", $val)) . '</a>'; //Strip extensions
            } else {
                $this->link = '<a href="/">' . $this->sitename . '</a>';
            } 
            $c++;
        } 
        return $this->link;
    } 

} //End Class 

?>

Here is a simple way to implement a "You Are Here" notification. Some people call this breadcrumbs, I don't. Here is the class, it works by simply grabbing it's location, and replacing the nasty forward slash("/"), with your choice of seperator. You can also choose a friendly name for your website, rather then just calling your site by it's domain name. It will also change underscores or hyphen to spaces, and make the first character of each word uppercase, ie. http://example.com/demo_page.php turns into: Example Site > Demo Page.

Usage: Text(); $link = $URHere->Link(); /* PHP < 4.2 should use this $text = $URHere->Text($PHP_SELF); $link = $URHere->Link($PHP_SELF); */ echo $text . "<br />"; echo $link; ?>

Created by Flinn Mueller on Tue, 4 Mar 2003 (MIT)
PHP recipes (51)
Flinn Mueller's recipes (1)

Required Modules

  • (none specified)

Other Information and Tasks