...

View Full Version : fwrite()



runeveryday
08-23-2009, 12:18 PM
<?php
$fp = fopen("text.txt", 'wb');
for ($j = 0 ; $j < 100 ; ++$j)
{
$written = fwrite($fp, "data");
if ($written == FALSE) break;
}
fclose($fp);
?>


when i had tested the above code,i found the result in text.txt is not one hundred data,but aonther?who can help me to see where is the error?
thanks!

abduraooft
08-23-2009, 12:31 PM
when i had tested the above code,i found the result in text.txt is not one hundred data,but aonther? Sorry, it's not clear.

runeveryday
08-23-2009, 12:42 PM
what a pity!in fact,in text.txt there are one hundred "data". but it does't. i don't know why.

funnymoney
08-23-2009, 01:02 PM
maybe this


<?php
$fp = fopen("text.txt", 'a+');
for ($j = 0 ; $j < 100 ; ++$j)
{
$written = fwrite($fp, "data");
if ($written == FALSE) break;
}
fclose($fp);
?>

runeveryday
08-23-2009, 02:15 PM
the result is the same as me.the following is the result that in the text.txt.
慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴 慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴 慤慴慤慴慤慴

runeveryday
08-25-2009, 04:26 AM
i got it.the truth is when i useed notepad to open the text.txt,it can't show "data"!but i used "zend studio" ,UltraEdit to open the text.txt,it can show "data".why?who can tell me?

DaiLaughing
08-25-2009, 06:48 AM
Different editors use different character encoding methods. Some can handle extended character sets including the characters you want. Others can only handle American plus a few extras.

tailender1
08-26-2009, 05:48 AM
you are forcing the text to be written in binary mode... use

$fp = fopen("text.txt", 'w');
this will fix the problem



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum