работа с переименованием фалов (str_replace)

Discussion in 'PHP' started by Vinsik, 12 Jan 2009.

  1. Vinsik

    Vinsik Elder - Старейшина

    Joined:
    4 Oct 2008
    Messages:
    189
    Likes Received:
    4
    Reputations:
    -5
    Я написал вот такой код
    PHP:
    $uniq strtolower(str_replace('а','a',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('б','b',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('в','v',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('г','g',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('д','d',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('е','e',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('ё','oh',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('ж','zh',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('з','z',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('и','i',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('й','j',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('к','k',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('л','l',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('м','m',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('н','n',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('о','o',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('п','p',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('р','r',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('с','s',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('т','t',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('у','u',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('ф','f',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('х','x',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('ц','c',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('ч','ch',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('ш','sh',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('щ','w',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('ъ','qh',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('ы','y',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('ь','q',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('э','eh',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('ю','ju',($_FILES['attached']['name'])));
                      
    $uniq strtolower(str_replace('я','ja',($_FILES['attached']['name'])));
    Обьясните мне почему он не работает? :(
     
  2. groundhog

    groundhog Elder - Старейшина

    Joined:
    12 May 2007
    Messages:
    1,159
    Likes Received:
    425
    Reputations:
    180
    Что не работает? Вардамп $_FILES что говорит?
     
  3. Vinsik

    Vinsik Elder - Старейшина

    Joined:
    4 Oct 2008
    Messages:
    189
    Likes Received:
    4
    Reputations:
    -5
    например файл назывался я я.mp3
    Он такой и остаеца) А должен переименоваца в ja_ja.mp3
    Када тока одна строчка
    например
    PHP:
     $uniq strtolower(str_replace('г','g',($_FILES['attached']['name']))); 
    Все отлично работает. Файл г.mp3 переименовываеца в g.mp3 а када все прописываю ниче не работает :(
     
  4. preda1or

    preda1or Member

    Joined:
    27 Oct 2008
    Messages:
    167
    Likes Received:
    96
    Reputations:
    6
    PHP:
    <?
    $ru=array("а","б","в","г","д","е","ё","ж","з","и","й","к","л","м","н","о","п","р","с","т","у","ф","х","ц","ч","ш","щ","ъ","ы","ь","э","ю","я");
    $tr=array("a","b","v","g","d","e","oh","zh","z","i","j","k","l","m","n","o","p","r","s","t","u","f","x","c","ch","sh","w","qh","y","q","eh","ju","ja");
    $uniq strtolower(str_replace($ru,$tr,$_FILES['attached']['name']));
    ?>
    Работает, и всего три строки, взамен твоих ~30.
     
    #4 preda1or, 12 Jan 2009
    Last edited: 12 Jan 2009
    3 people like this.
  5. Vinsik

    Vinsik Elder - Старейшина

    Joined:
    4 Oct 2008
    Messages:
    189
    Likes Received:
    4
    Reputations:
    -5
    +10 !!!! Я по тупому накатал) Блин надо же было НЕ догадатся переменные ввести.
     
    1 person likes this.
  6. 6G3TCH

    6G3TCH New Member

    Joined:
    7 Jan 2009
    Messages:
    8
    Likes Received:
    2
    Reputations:
    0
    PHP:
    <? 
    $ru=array("а","б","в","г","д","е","ё","ж","з","и","й","к","л","м","н","о","п","р","с","т","у","ф","х","ц","ч","ш","щ","ъ","ы","ь","э","ю","я"); 
    $tr=array("a","b","v","g","d","e","oh","zh","z","i","j","k","l","m","n","o","p","r","s","t","u","f","x","c","ch","sh","w","qh","y","q","eh","ju","ja"); 
    $uniq str_replace($ru,$tr,strtolower($_FILES['attached']['name']));
    ?>
    так лучше наверное ;)