Here is the code that transliterates the text and displays the result in a browser. How do I save the result to a file ??

<?php $transliter = file_get_contents("trn.txt"); $trans = array("а"=>"a","б"=>"b","в"=>"v","г"=>"g","д"=>"d","е"=>"e", "ё"=>"yo","ж"=>"j","з"=>"z","и"=>"i","й"=>"i","к"=>"k","л"=>"l", "м"=>"m","н"=>"n","о"=>"o","п"=>"p","р"=>"r","с"=>"s","т"=>"t", "у"=>"y","ф"=>"f","х"=>"h","ц"=>"c","ч"=>"ch", "ш"=>"sh","щ"=>"sh","ы"=>"i","э"=>"e","ю"=>"u","я"=>"ya","А"=>"A","Б"=>"B","В"=>"V","Г"=>"G","Д"=>"D","Е"=>"E", "Ё"=>"Yo","Ж"=>"J","З"=>"Z","И"=>"I","Й"=>"I","К"=>"K", "Л"=>"L","М"=>"M","Н"=>"N","О"=>"O","П"=>"P", "Р"=>"R","С"=>"S","Т"=>"T","У"=>"Y","Ф"=>"F", "Х"=>"H","Ц"=>"C","Ч"=>"Ch","Ш"=>"Sh","Щ"=>"Sh", "Ы"=>"I","Э"=>"E","Ю"=>"U","Я"=>"Ya","ь"=>"","Ь"=>"","ъ"=>"","Ъ"=>""); echo strtr("$transliter", $trans); ?> 

    2 answers 2

    A simple example of creating a file (will create, if it does not exist) from an entry into it.

     <?php $result = ''; $fname = './fname.txt'; $fileLink = fopen($fname, 'wb'); fwrite($fileLink, $result); fclose($fileLink); ?> 
    • Result-Warning: fwrite () expects parameter 2 to be string, array given in Z: \ home \ localhost \ www \ trans.php on line 10 - multidor
    • What exactly do you need to do? What result will you get from the function strtr ("$ transliter", $ trans); ? - Andrei Arshinov
    • transliterated text from trn.txt file - multidor
    • thanks for the answer did everything. - multidor

    Read about file_put_contents () .

    • then just the file is written to the file - multidor
    • file_put_contents('file.txt', strtr($transliter, $trans)); - did you do it? - ling
    • No, not so, thank you for a long time tormented. - multidor