PHP: Split string into chunks of 8, how do I do this?

老子叫甜甜 提交于 2019-12-22 05:58:11

问题


I have binary basically, say it's 300 in length. How would I split (much like using explode) it into 8 bit chunks? I look at chunk_split() but it only seems to have an 'end' parameter, not an option to put it into an array.. Or can it be socketed into an array?

The end 8 digits can be below 8 (in case a miscopy from someone, and it's 4) so no validation is needed, just consistantly in 8 number chunks from the start to end.


回答1:


str_split:

$chunks = str_split($data, 8);


来源:https://stackoverflow.com/questions/2191199/php-split-string-into-chunks-of-8-how-do-i-do-this

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!