Click here to Skip to main content
15,867,860 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi I have this code:
HTML
<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
    <meta charset="utf-8"/>
</head>
<body>
<style>
*{
	font-family:tahoma;
}
</style>
<center>
	<?php
	$dir="./texts";
	if ($handle = opendir($dir)) {
		while (false !== ($file = readdir($handle))) {
			echo "<div class='_item'>";
			echo "<a href='".utf8_decode($file)."'></a><br />";
			echo "</div>";
		}
		closedir($handle);
	}
	
	
	
	?>
</center>
</body>
</html>


and i have this files in this dir "./texts":
test.txt
تست.txt


but i get this:
.
..
test
���


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

1 solution

What would you expect? You did not properly specify the charset. It should be
HTML
<html>
	<head>
		<!-- ... -->
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	</head>
<body>
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: https://developer.mozilla.org/en-US/docs/Web/CSS/direction[^].

—SA
 
Share this answer
 
v5
Comments
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?
—SA
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.
—SA

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