How to split a string in PHP
I have a long string resulted from en开发者_开发知识库coding 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.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)
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()
.
chunk_split (string $body [, int $chunklen [, string $end ]] )
精彩评论