473,325 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Save Unicode Text File

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
3 3388
hsriat
1,654 Expert 1GB
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
Hi - Thanks. I just installed the mbstring library and that fixed the problem. Sorry for the confusion!
Jun 23 '08 #3
hsriat
1,654 Expert 1GB
Ok, that's great :)
Jun 23 '08 #4

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

Similar topics

6
by: ..... | last post by:
I have an established program that I am changing to allow users to select one of eight languages and have all the label captions change accordingly. I have no problems with English, French, Dutch,...
3
by: Michael Weir | last post by:
I'm sure this is a very simple thing to do, once you know how to do it, but I am having no fun at all trying to write utf-8 strings to a unicode file. Does anyone have a couple of lines of code...
3
by: hunterb | last post by:
I have a file which has no BOM and contains mostly single byte chars. There are numerous double byte chars (Japanese) which appear throughout. I need to take the resulting Unicode and store it in a...
1
by: David Dvali | last post by:
Hello. I have a problem with sending Unicode text in mail message. So what I do: First of all I have some template file like this: ================================= <html> <head><title>Test...
10
by: Nikolay Petrov | last post by:
How can I convert DOS cyrillic text to Unicode
18
by: Ger | last post by:
I have not been able to find a simple, straight forward Unicode to ASCII string conversion function in VB.Net. Is that because such a function does not exists or do I overlook it? I found...
8
by: david.lindsay.green | last post by:
Hello all, I am quite new a web scripting and making web pages in general and I have stumbled across a problem I have as yet been unable to solve. I am trying to take the contents of a textarea box...
0
by: joffypf | last post by:
hi how can save utf-8 encoded string to a text file. I tryed to save unicode string but unicode string only display just ike '????'. please help me...
1
by: hugobotha | last post by:
Hi All, I have a problem when saving a text file as a html file in unicode and then google index the Unicode bom as well as I can not open these files. I have a asp page that takes another asp...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.