need help in my php code getting wrong directory on breadcrumb

前端 未结 1 1541
无人共我
无人共我 2021-01-27 11:51

my php breadcrumb code is below and the problem is, this is my directory

http://domain.com/folder

using the code below i get directory like this

Ho

相关标签:
1条回答
  • 2021-01-27 12:25

    Start the for loop which uses $i as index with initial value 2 instead of 1.

    <?php
        $file = basename("/".$_SERVER["PHP_SELF"]);
    
        $filename = (count(explode('.', $file)) === 1 ? $file : implode('.', array_slice(explode('.', $file), 0, (count(explode('.', $file))-1))));
        $Pages = array(
            $filename => 'Folder'
        );
    
        $path = "/".$_SERVER["PHP_SELF"];
        $parts = explode('/',$path);
        if (count($parts) < 2)
        {
        echo("home");
        }
        else
        {
        echo ("<a href=\"http://domain.com\">Home</a>  ");
        $cnt = count($parts);
        for ($i = 1; $i < $cnt; $i++)
            {
            if (!strstr($parts[$i],"."))
                {
                echo("&raquo; <a href=\"");
                for ($j = 0; $j <= $i; $j++) {echo $parts[$j]."/";};
                echo("\">". str_replace('-', ' ', $Pages[$parts[$i]])."</a> ");
                }
            else
                {
                $str = $parts[$i];
                $pos = strrpos($str,".");
                $parts[$i] = substr($str, 0, $pos);
                echo str_replace('-', ' ', $Pages[$parts[$i]]);
                };
            };
        };  
    ?>

    0 讨论(0)
提交回复
热议问题