By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,694 Members | 1,882 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,694 IT Pros & Developers. It's quick & easy.

Save Unicode Text File

P: 2
When I pull a string from a UTF-8 encoded field in my SQL, I get a string like the following:

"& #2342;& #2369;& #2312;"

(I have inserted a space between "&" and "#" to stop this from displaying as international text, in my actual string there is no space).

This is a string of escaped characters, length of the string is 21 but it is actually representing something (international text) that is 3 characters.

Now I would like to save these 3 characters to a file. This file should be 6 (3 x 2) bytes long. But, of course, when I use fwrite with the above string I get a file of 21 bytes.

I could parse the string to get the six hex values (23,42,23,69,23,12) that I would need to write, but I can't even get PHP to output true binary. The following:

Expand|Select|Wrap|Line Numbers
  1. $fh = fopen("text.txt", "wb");
  2. fwrite($fh, (int)32);
  3.  
Outputs the number 32 in ASCII, not one byte of value 0x20. This is despite the "b" open mode! Can anyone help me with this? Ultimate goal is to save the above characters as described. Thanks!
Jun 22 '08 #1
Share this Question
Share on Google+
3 Replies


hsriat
Expert 100+
P: 1,654
It seems you have somewhere done wrong encoding.

Can you show the snippet of your code to let us locate the error?
Jun 23 '08 #2

P: 2
Hi - Thanks. I just installed the mbstring library and that fixed the problem. Sorry for the confusion!
Jun 23 '08 #3

hsriat
Expert 100+
P: 1,654
Ok, that's great :)
Jun 23 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.