php中2进制如何转文本流(php,编程语言)

时间:2024-05-03 03:11:14 作者 : 石家庄SEO 分类 : 编程语言
  • TAG :

php 2进制转文本流的方法:1、创建一个PHP示例文件;2、通过“function bin2text($bin_str){...}”方法实现二进制转换为文本即可。

php中2进制如何转文本流

本文操作环境:Windows7系统,PHP7.4版,Dell G3电脑。

php实现二进制和文本相互转换的方法

这段代码包含两个函数,bin2text,二进制转换为文本,text2bin,文本转换成二进制

<?phpfunctionbin2text($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;}functiontext2bin($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;}printtext2bin('Howareyougentlements?');?>


 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:php中2进制如何转文本流的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:php中gbk转utf8用哪个函数下一篇:

4 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18