2016-08-02 8 views
1

업로드하는 동안 이미지에 슬러그 이름을 넣으려고합니다. str_replace으로 테스트했지만 작동하지 않습니다.이미지 POST PHP 슬러그

$_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; 
} 

는 난 단지 파일 이름 인 경우 a,e,i,o,u

á,é,í,ó,ú 같은 - 및 문자 blank spaces를 제거해야합니다 "prueba para Guardar ímagen ñueva.png"

가되어야합니다 "prueba-para-guardar-imagen-nueva.png"

감사합니다! 원하는 행동에 대한

+0

를나요? –

+0

예, 작동하지 않습니다. –

답변

0

당신이 첫 번째 행 \.

// replace non letter or digits by - 
$text = preg_replace('~[^\pL\d\.]+~u', '-', $text); 

과 세 번째 행에 추가 할 필요가 너무 \.

// remove unwanted characters 
$text = preg_replace('~[^-\w\.]+~', '', $text); 
이없는 str_replace에
+0

완벽하게 작동합니다! 대단히 감사합니다 !! 원본 :'prueba para Guardar ímagen ñueva.png' 결과 :'prueba-para-guardar-i-magen-n-ueva.png' –

+0

내 기쁨. 도와 줘서 기뻐요 :-) –