php 2进制转文本流的方法 1. 创建一个php示例文件; 2. 通过“function bin2text($bin,str){...}”方法实现二进制转换为文本即可。
本文操作环境windows7系统,php7.4版,dell g3电脑。
php 2进制怎么转文本流?
php实现二进制和文本相互转换的方法
这段代码包含两个函数,bin2text,二进制转换为文本,text2bin,文本转换成二进制
<?phpfunction bin2text($bin,str){ $text,str = ''; $chars = explode(\\n,chunk,split(str,replace(\\n,'',$bin,str),8)); $,i = count($chars); for($i = 0; $i < $,i; $text,str .= chr(bindec($chars[$i])), $i ); return $text,str;}function text2bin($txt,str){ $len = strlen($txt,str); $bin = ''; for($i = 0; $i < $len; $i ) { $bin .= strlen(decbin(ord($txt,str[$i])))<8?str,pad(decbin(ord($txt,str[$i])),8,0,str,pad,left):decbin(ord($txt,str[$i])); } return $bin;}print text2bin('how are you gentlements?');?>推荐学习《php视频教程》