0

I got a php form which write fields in text files. php file is utf8 and created files are utf8 too. (for persian language I need utf8) problem: when I open created file for example: post.txt in browser, I get something like:

ªÛŒØªØ± مطلب:
لینک ØµÙØ­Ù‡:
آدرس تصویØ

Code

<html dir="rtl">

<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
<title>خبررسان</title>
<style type="text/css">
.form {
    font-family: Tahoma;
    font-size: 11px;
}
</style>
</head>

<body class="form" style="margin: 0">
<?php
if($_POST['Submit'])

{

$title = $_POST['title'];

$link = $_POST['link'];

$image = $_POST['image'];

$post = $_POST['post'];


$postid = rand(0, 999999999);

//open the file and choose the mode

$fh = fopen("last.txt", "w");

fwrite($fh, $postid);

//close the file

fclose($fh);






//open the file and choose the mode

$fh = fopen("title.txt", "w");

fwrite($fh, $title);

//close the file

fclose($fh);

//open the file and choose the mode

$fh = fopen("link.txt", "w");

fwrite($fh, $link);

//close the file

fclose($fh);

//open the file and choose the mode

$fh = fopen("image.txt", "w");

fwrite($fh, $image);

//close the file

fclose($fh);

//open the file and choose the mode

$fh = fopen("post.txt", "w");

fwrite($fh, $post);

//close the file

fclose($fh);



header("Location:index.php");

}

else

{

print <<<ENDOFTXT

</style><form name="form1" method="post" action="index.php">

<table border="0" align="center">

<tr>

<td><span class="style5">تیتر مطلب:</span></td>

<td><input name="title" type="text" id="title" style="font-family: tahoma"></td>

</tr>

<tr>

<td><span class="style5">لینک صفحه:</span></td>

<td><input name="link" type="text" id="link" value="" style="font-family: tahoma"></td>

</tr>

<tr>

<td><span class="style5">آدرس تصویر:</span></td>

<td><input name="image" type="text" id="image" style="font-family: tahoma"></td>

</tr>

<tr>

<td><span class="style5">مطلب:</span></td>

<td><textarea name="post" id="post" rows="5" cols="30" style="font-family: tahoma"></textarea></td>

</tr>

<tr>

<td><input name="Submit" type="submit" class="style5" value="ارسال مطلب به مخاطبین من" style="font-family: tahoma"></td>

</tr>

<tr>

<td colspan="2"><div align="center"></div></td>

</tr>

</table>

<p align="center">&nbsp;</p>

</form>

ENDOFTXT;

}
?>
</body>

</html>

1 Answer 1

2

the problem is likely caused by incorrect charset headers sent by your webserver. If you are using an apache2 webserver, create a file called .htaccess and put: AddDefaultCharset UTF-8 into it.

This should tell apache to deliver a Content-Type:utf-8 header and fix your encoding problems. Another solution would be to make a small HTML page that delivers the text file together with the meta-encoding header.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.