Jump to content


Photo

Why is binary mode missing from fopen() modes?


Best Answer kicken, 27 July 2014 - 05:02 PM

Not sure what you mean by it being missing. The binary flag is mentioned. They just don't list r and rb as different modes because it's unnecessary.

Windows offers a text-mode translation flag ('t') which will transparently translate \n to \r\n when working with the file. In contrast, you can also use 'b' to force binary mode, which will not translate your data. To use these flags, specify either 'b' or 't' as the last character of the mode parameter.

Go to the full post


  • Please log in to reply
6 replies to this topic

#1 johnmerlino1

johnmerlino1
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 27 July 2014 - 06:54 AM

I was looking at the manual:

 

http://php.net/manua...ction.fopen.php

 

And I noticed the the binary mode 'b' is missing from the list. Any reason why?



#2 ginerjm

ginerjm
  • Members
  • PipPipPip
  • Handball player
  • 4,129 posts
  • LocationVoorheesville NY

Posted 27 July 2014 - 01:54 PM

Same for the 't' mode.  I think it is because there are so many caveats mentioned in the comments that one needs to be "more" aware of how and why to use both 'b' and 't' mode.


JG
PS - If you're posting here you should be using:
        error_reporting(E_ALL);
        ini_set('display_errors', '1');

at the top of ALL php code while you develop it!

#3 johnmerlino1

johnmerlino1
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 27 July 2014 - 03:25 PM

Same for the 't' mode.  I think it is because there are so many caveats mentioned in the comments that one needs to be "more" aware of how and why to use both 'b' and 't' mode.

 

But if I want to open a file for reading, can I just use r or do I need to attach b as well?

 

$fp = fopen(“$DOCUMENT_ROOT/../orders/orders.txt”, ‘rb’);
 



#4 ginerjm

ginerjm
  • Members
  • PipPipPip
  • Handball player
  • 4,129 posts
  • LocationVoorheesville NY

Posted 27 July 2014 - 03:42 PM

Read the manual and decide for yourself.


JG
PS - If you're posting here you should be using:
        error_reporting(E_ALL);
        ini_set('display_errors', '1');

at the top of ALL php code while you develop it!

#5 kicken

kicken
  • Gurus
  • Wiser? Not exactly.
  • 3,361 posts
  • LocationBonita, FL

Posted 27 July 2014 - 05:02 PM   Best Answer

Not sure what you mean by it being missing. The binary flag is mentioned. They just don't list r and rb as different modes because it's unnecessary.

Windows offers a text-mode translation flag ('t') which will transparently translate \n to \r\n when working with the file. In contrast, you can also use 'b' to force binary mode, which will not translate your data. To use these flags, specify either 'b' or 't' as the last character of the mode parameter.


Did I help you out? Feeling generous? I accept tips via Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7
Kicken's World⦄ ⦃Recycle old CD's

#6 johnmerlino1

johnmerlino1
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 27 July 2014 - 05:02 PM

Read the manual and decide for yourself.

Well, I linked the manual to the original question and that actually indeed was my question - why is this mode missing and since it is missing, is it not needed anymore in PHP5?



#7 ginerjm

ginerjm
  • Members
  • PipPipPip
  • Handball player
  • 4,129 posts
  • LocationVoorheesville NY

Posted 27 July 2014 - 06:42 PM

It's been explained twice to you.  If your entire question is simply curiosity about the option, then you won't get anymore here.  And if your concern is about the accuracy of the manual, well then, you are going to have a field day with other functions.

 

Signing off - too boring.


JG
PS - If you're posting here you should be using:
        error_reporting(E_ALL);
        ini_set('display_errors', '1');

at the top of ALL php code while you develop it!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users