Click here to Skip to main content
15,665,444 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi I have this code:
<!DOCTYPE html>
<html lang="fa" dir="rtl">
    <meta charset="utf-8"/>
	if ($handle = opendir($dir)) {
		while (false !== ($file = readdir($handle))) {
			echo "<div class='_item'>";
			echo "<a href='".utf8_decode($file)."'></a><br />";
			echo "</div>";

and i have this files in this dir "./texts":

but i get this:

i can't get تست with right encoding. :(
Updated 20-May-20 15:38pm

1 solution

What would you expect? You did not properly specify the charset. It should be
		<!-- ... -->
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
And, of course, you need to actually write the text in Unicode and save your file in UTF-8. :-)

And perhaps you should not forget about RTL design:[^].

Share this answer
Behnam Mohammadi 18-Jul-15 8:38am    
i change that line to <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> but still not working and i fetch strings from file name i can't set encoding for that
Sergey Alexandrovich Kryukov 18-Jul-15 8:43am    
Can you see this: "فارسی کار می کند"?
And this is how the present page works. So it should work for you, too. Can you show some complete HTML sample with just one line in Persian? And did you actually use UTF-8?
Sergey Alexandrovich Kryukov 18-Jul-15 8:50am    
Oh, and the rhombus-shaped characters at the end show that you might have used some font which does not support Unicode at all, or does not support Perso-Arabic script, which is a rare thing, because this script and Unicode subset is supported by default on nearly all modern platforms. If you used no font-family at all, Persian should be always shown, as it happens on this page.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900