<!--Breadcrumb ------------------------->
<div class="breadcrumb">
<!--previous page--><a href="javascript:history.go(-1)"><img src="https://www.xxx.com/images/arrow/back.buttons.png" alt="back"></a>
<?php
$path = $_SERVER["PHP_SELF"];
$parts = explode('/',$path);
if (count($parts) < 2)
{
echo("home");
}
else
{
echo ("<a href=\"/\">home</a>");
for ($i = 1; $i < count($parts); $i++)
{
if (!strstr($parts[$i],"."))
{
echo("<a href=\"");
for ($j = 0; $j <= $i; $j++) {echo $parts[$j]."/";};
echo("\">". str_replace('-', ' ', $parts[$i])."</a>");
}
else
{
$str = $parts[$i];
$pos = strrpos($str,".");
$parts[$i] = substr($str, 0, $pos);
echo str_replace('-', ' ', $parts[$i]);
};
};
};
?>
</div>
<!------------------------Breadcrumb -->
การแก้ไข ให้ไม่แสดงชื่อไฟล์สุดท้าย
<?php
$path = $_SERVER["PHP_SELF"];
$parts = explode('/',$path); :
how not display the final file of path?
<?php
$path = $_SERVER["PHP_SELF"];
$parts = explode('/', $path);
array_pop($parts); // remove the last element
$directory = implode('/', $parts); // join the remaining segments with '/'
echo $directory; // display the directory path
?>
การแก้ทั้งโค๊ด
<?php
$path = $_SERVER["PHP_SELF"];
$parts = explode('/',$path);
if (count($parts) < 2)
{
echo("home");
}
else
{
echo ("<a href=\"/\">home</a>");
array_pop($parts); // remove the last element
for ($i = 1; $i < count($parts); $i++)
{
if (!strstr($parts[$i],"."))
{
echo("<a href=\"");
for ($j = 0; $j <= $i; $j++) {echo $parts[$j]."/";};
echo("\">". str_replace('-', ' ', $parts[$i])."</a>");
}
else
{
$str = $parts[$i];
$pos = strrpos($str,".");
$parts[$i] = substr($str, 0, $pos);
echo str_replace('-', ' ', $parts[$i]);
};
};
};
?>
เขียนให้สั้นลง และแสดงไฟล์สุดท้ายด้วย
<?php
$path = $_SERVER["PHP_SELF"];
$parts = explode('/',$path);
echo count($parts) < 2 ? "home" : "<a href=\"/\">home</a>";
for ($i = 1; $i < count($parts) - 1; $i++)
{
echo "<a href=\"";
for ($j = 0; $j <= $i; $j++) {echo $parts[$j]."/";};
echo "\">".str_replace('-', ' ', $parts[$i])."</a>";
};
echo str_replace('-', ' ', $parts[count($parts)-1]);
?>
เขียนให้สั้น และไม่แสดงไฟล์สุดท้าย
โดยตั้งคำถาม
the shot code you tell me not working ,please modify in shot code by use this code base : (แล้วใส่ code เต็มลงไป)
หรือ
modified code that is shorter and does not display the final file of the path
<?php
$parts = explode('/', $_SERVER["PHP_SELF"]);
echo count($parts) < 2 ? "home" : "<a href=\"/\">home</a>";
array_pop($parts); // remove the last element
for ($i = 1; $i < count($parts); $i++) {
if (!strstr($parts[$i], ".")) {
echo "<a href=\"" . implode('/', array_slice($parts, 0, $i+1)) . "/\">" . str_replace('-', ' ', $parts[$i]) . "</a>";
} else {
$str = $parts[$i];
$pos = strrpos($str, ".");
$parts[$i] = substr($str, 0, $pos);
echo str_replace('-', ' ', $parts[$i]);
}
}
?>
เปลี่ยนไปใช้ previous page อย่างเดียว
<div class="breadcrumb">
<!--previous page--><a href="javascript:history.go(-1)"><img src="https://www.xxx.com/images/arrow/back.buttons.png" alt="back"></a>
</div>