Connecting Tech Pros Worldwide Help | Site Map

Save Unicode Text File

Newbie
 
Join Date: Jun 2008
Posts: 2
#1: Jun 22 '08
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!
hsriat's Avatar
Expert
 
Join Date: Jan 2008
Location: Bath, UK
Posts: 1,609
#2: Jun 23 '08

re: Save Unicode Text File


It seems you have somewhere done wrong encoding.

Can you show the snippet of your code to let us locate the error?
Newbie
 
Join Date: Jun 2008
Posts: 2
#3: Jun 23 '08

re: Save Unicode Text File


Hi - Thanks. I just installed the mbstring library and that fixed the problem. Sorry for the confusion!
hsriat's Avatar
Expert
 
Join Date: Jan 2008
Location: Bath, UK
Posts: 1,609
#4: Jun 23 '08

re: Save Unicode Text File


Ok, that's great :)
Reply