我想在這裏做什麼,在我的PHP代碼下面我必須手動設置文件名,我想使它一些如何抓住文件名自動但沒有文件擴展獲取文件名沒有文件擴展名在我的PHP代碼
此處,我想文件名
$Pages = array(
'clothes' => 'Clothes',
'shirt' => 'shirt',
'this-shirt' => 'This Shirt'
);
它說:「這個恤」是文件名,我希望它自動設置的,而不是我寫下來,我的代碼部分每次我創建一個頁面。這裏的完整代碼
<?php
$Pages = array(
'clothes' => 'Clothes',
'shirt' => 'shirt',
'this-shirt' => 'This Shirt'
);
$path = $_SERVER["PHP_SELF"];
$parts = explode('/', $path);
if (count($parts) < 2) {
echo("home");
} else {
echo ("<a href=\"http://domain.com\">Home</a> » ");
for ($i = 2; $i < count($parts); $i++) {
if (!strstr($parts[$i], ".")) {
echo("<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]]);
}
}
}
希望你明白了。感謝
'$文件= '這-shirt.pdf'; $ filename =(count(explode('。',$ file))=== 1?$ file:implode('。',array_slice(explode('。',$ file),0,(count(explode(' 。',$ file)) - 1)))); echo $ filename;' – MonkeyZeus
@MonkeyZeus親愛的你可以請發表你的代碼在答案?因爲它不是這樣清楚的 –
哪個變量包含帶有**擴展名的「this-shirt **」? – MonkeyZeus