Search code examples
phpencodingutf-8characternon-english

How to display non english characters in php?


I've a basic question in PHP:

I've 2 files: An HTML form with a Textarea and a PHP file. All I want is to print the text the user types after submit is pressed. It all goes well when only English characters are typed but I get gibberish when I type Arabic or Chinese for instance. Is there a way to display all the characters?

Here is the code of the PHP file:

<?php
     $txt = $_GET['toTranslate'];
     echo $txt;
?>

Solution

  • Please try to add

    header('Content-Type: text/plain; charset=UTF-8');
    

    or Add set as html and set

    echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
    echo $txt;