Reputation: 314
I am using this code for reading a file which contains Hindi alphabets.
<?php
$arrbyline=file('E:\HindiFile.txt');
foreach($arrbyline as $lines)
{
echo $lines . "<BR>";
}
HindiFile.txt:
नमस्कार सज्जनों
But I am getting this:
ÿþ( . 8 M > 0 8 M ( K
Here, I am getting unknown characters. How can I get my Hindi chars?
Upvotes: 2
Views: 2201
Reputation: 4403
first of all you should save your file in utf-8
. then
read your file like this:
if (file_exists($SourceDirectoryFile))
{
$NameBook = "HindiFile.txt";
$contents = file_get_contents($NameBook);
// browser should display UTF-8 characters
header('Content-Type: text/html; charset=UTF-8');
echo $contents . '<hr/>';
}
Upvotes: 1