クライアントが指定したページのタイトルに基づいてページを作成する CMS を作成しました。
たとえば、「About Us」は「about-us.php」として作成されます
現在、次を使用して、許可されていないすべての文字を取り除きます。ページを編集して別の名前を呼び出すときのコードを追加して、ファイルの名前を変更します。
function toAscii($str) {
$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $str);
$clean = strtolower(trim($clean, '-'));
$clean = preg_replace("/[\/_|+ -]+/", '-', $clean);
return $clean;
}
// Renames the file
rename(toAscii($row_Recordset1['content_title']).".php", toAscii($_POST['content_title']).".php");
しかし、これらの特殊文字を本当に許可したいので、上記の関数を次のように変更しました。
function toAscii($str) {
$clean = strtolower($str);
$clean = str_replace(";", "%3B", $clean);
$clean = str_replace("/;", "%2F", $clean);
$clean = str_replace("?", "%3F", $clean);
$clean = str_replace(":", "%3A", $clean);
$clean = str_replace("&", "%26", $clean);
$clean = str_replace("@", "%40", $clean);
$clean = str_replace("=", "%3D", $clean);
$clean = str_replace(" ", "-", $clean);
return $clean;
}
// Renames the file
rename(toAscii($row_Recordset1['content_title']).".php", toAscii($_POST['content_title']).".php");
エレガントではないことはわかっていますが、理論的には機能するはずです。
そうではありません。
したがって、ファイル名が「shows-%2F-exhibitions.php」である必要がある場合、実際には「shows-/-exhibitions.php」として表示されますが、これは明らかに許可されていません。
16進コードを適用して再びスラッシュで終わるのではなく、ファイル名に16進コードを保持させるにはどうすればよいですか?
それとも、URL にスラッシュを使用することは許可されていませんか?