views:

314

answers:

3

Hello,
I have a long string resulted from encoding a binary file -an image file- (in base 64). Is there a particulary method (or rule) I should follow when spliting it?
Edit:
I want to write the string to a xml file, but in order to do this I must split it in smaller chunks.
Edit2:
I would like to split it by length (I think that is more appropriate in this case).
Thank you.

+3  A: 

Use explode() or preg_split() as appropriate. All data in PHP is technically binary, even character data. If your data is multibyte character data (eg UTF-8) you'll need extra steps to correctly handle that.

Also binary strings may need processing with unpack().

cletus
+4  A: 

You might want to take a look at chunk_split, since you do base64 encoding. (Assuming you do encoding, since you can't embed decoded base64 data in XML files)

Boldewyn
Yes, i was talking about encoding. My bad. Thanks Boldewyn.
sica07