Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8

Thread: fwrite()

  1. #1
    Regular Coder
    Join Date
    Jul 2009
    Posts
    152
    Thanks
    8
    Thanked 0 Times in 0 Posts

    fwrite()

    PHP Code:
    <?php
    $fp 
    fopen("text.txt"'wb');
    for (
    $j $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!

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    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.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Jul 2009
    Posts
    152
    Thanks
    8
    Thanked 0 Times in 0 Posts
    what a pity!in fact,in text.txt there are one hundred "data". but it does't. i don't know why.

  • #4
    Regular Coder funnymoney's Avatar
    Join Date
    Aug 2007
    Posts
    364
    Thanks
    17
    Thanked 24 Times in 24 Posts
    maybe this
    PHP Code:
    <?php
    $fp 
    fopen("text.txt"'a+');
    for (
    $j $j 100 ; ++$j)
    {
    $written fwrite($fp"data");
    if (
    $written == FALSE) break;
    }
    fclose($fp);
    ?>

  • #5
    Regular Coder
    Join Date
    Jul 2009
    Posts
    152
    Thanks
    8
    Thanked 0 Times in 0 Posts
    the result is the same as me.the following is the result that in the text.txt.
    慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴 慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴慤慴 慤慴慤慴慤慴

  • #6
    Regular Coder
    Join Date
    Jul 2009
    Posts
    152
    Thanks
    8
    Thanked 0 Times in 0 Posts
    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?

  • #7
    Regular Coder
    Join Date
    Jul 2009
    Posts
    136
    Thanks
    0
    Thanked 7 Times in 7 Posts
    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.

  • #8
    New Coder
    Join Date
    Aug 2009
    Posts
    26
    Thanks
    1
    Thanked 3 Times in 3 Posts
    you are forcing the text to be written in binary mode... use
    PHP Code:
    $fp fopen("text.txt"'w'); 
    this will fix the problem


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •