Upload .txt file by removing php accents [duplicate]

1

I need some way for me to upload a .txt file and all the text is stored in a array to later wipe this array and remove all accents from the text, after that generate the .txt file without the accents? (Take the accents out of the content that is inside the .txt file.)

    
asked by anonymous 17.08.2016 / 19:04

1 answer

3

Do this:

<form enctype="multipart/form-data" method="POST">
    <input type="file" name="txt">
    <input type="submit">
</form>
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
    $file = $_FILES['txt'];
    $dir = 'tests/'; // ajustar nome diretório destino
    $fileName = 'new_txt.txt'; // ajustar nome do ficheiro
    move_uploaded_file($file['tmp_name'], $dir.$fileName);
    $text = utf8_encode(file_get_contents($dir.$fileName);
    $search = explode(",","ç,æ,œ,á,é,í,ó,ú,à,è,ì,ò,ù,ä,ë,ï,ö,ü,ÿ,â,ê,î,ô,û,å,e,i,ø,u");
    $replace = explode(",","c,ae,oe,a,e,i,o,u,a,e,i,o,u,a,e,i,o,u,y,a,e,i,o,u,a,e,i,o,u");
    $new_text = str_replace($search, $replace, $text);
    $file = fopen($dir.$fileName, 'w');
    fwrite($file, $new_text);
    fclose($file);
    echo 'VELHO TEXTO:<br><br>' .$text. '<br><br>';
    echo 'NOVO TEXTO:<br><br>' .file_get_contents($dir.$fileName);
}

Fit where I said "adjust ..."

    
17.08.2016 / 19:44