Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hello, everyone.
I have s php script that reads a contents of a file to TEXTAREA html element. After I post this contents back to the server via form, and the same script writes it back to the file. The problem is that php adds some non-ascii characters to a file.
Please, help me resolve this.
Here is the script:Code: Select all
<?
$file="file.txt";
if ($_POST['save']=='1') {
$handle=fopen($file,'w');
$data=fwrite($handle,$_POST['data']);
fclose($handle);
}
$handle=fopen($file,'r');
$data=fread($handle,filesize($file));
fclose($handle);
?>
<html><body><form action=<? echo $_SERVER['PHP_SELF']; ?> method=POST><textarea name=data><? echo $data; ?></textarea><input type=hidden name=save value=1><br><input type=s
ubmit value=Ok></form></body></html>When I do diff to a file before and after modification by this script, it returns the following:
Code: Select all
user@laptop# diff file.txt file2.txt
1,4c1,4
< 1234
< qwer
< asdf
< zxcv
---
> 1234
> qwer
> asdf
> zxcvfeyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]