アップロード中に画像にスラッグ名を付けようとしています。テストしてstr_replace
いましたが、機能しません。
$_FILES['imgProfile']['name'] = str_replace("í", "i", $_FILES['imgProfile']['name']);
次のようなものを返します:i?magen.png
画像をアップロードしません。
この機能を試してみましたが、ファイル拡張子が削除されます。
function slugify($text)
{
// replace non letter or digits by -
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
// transliterate
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);
// trim
$text = trim($text, '-');
// remove duplicate -
$text = preg_replace('~-+~', '-', $text);
// lowercase
$text = strtolower($text);
if (empty($text)) {
return 'n-a';
}
return $text;
}
blank spaces
withとwith-
のような文字のみを削除する必要がありますá,é,í,ó,ú
a,e,i,o,u
ファイル名が次の場合:"prueba para Guardar ímagen ñueva.png"
それは違いない:"prueba-para-guardar-imagen-nueva.png"
ありがとう!