我有一個代碼正在工作,因爲我想從1個問題中分離出來。從文件中刪除擴展名
你可以在這裏看到結果http://test.whatanswered.com/health/what-can-a-first-aider-do.php在「相關文章」下面顯示死鏈接。
以下是應該顯示的HTML。
<p><a href="../health/name-of-the-page.php">Name of the page</a></p>
我想剝離破折號和PHP作爲上述「頁面名稱」,但它也剝去從URL破折號和PHP。
的代碼是:
<?php
if ($handle = opendir('health')) {
$fileTab = array();
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$fileTab[$file] = strtr(pathinfo($file, PATHINFO_FILENAME), '-', ' ');
}
}
closedir($handle);
shuffle($fileTab);
foreach(array_slice($fileTab, 0, 10) as $file => $health) {
$thelist .= '<p><a href="../health/'.$file.'">'.$health.'</a></p>';
}
}
?>
<?=$thelist?>
pathinfo($ myFile,PATHINFO_FILENAME)和str_replace()....閱讀說明書有幫助 –
對不起,但我不明白你在問什麼。你能否以更清楚的方式嘗試措辭這個問題? – Charles