欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

php二进制输出|php字符转二进制|php二进制字符转换

程序员文章站 2022-05-16 23:41:04
...
php二进制输出|php字符转二进制|php二进制字符转换
<?php
header('Content-type:text/html; charset=utf-8');

class binaryString{
	
	protected $split = '&';
	
	public function bin2str($bin, $str = ''){
		$list = explode($this->split, $bin);
		foreach($list as $val){
			$str .= chr(bindec($val));	
		}
		return $str;
	}
	
	public function str2bin($str, $bin = array()){
		$len = mb_strlen($str);
		for($i = 0; $i < $len; $i ++){
			$bin[] = decbin(ord($str{$i}));
		}
		return implode($this->split, $bin);
	}
		
}

$b = new binaryString;

echo $s = $b->str2bin('这是字符转二进制输出的示例');

echo $b->bin2str($s);

以上就是php二进制输出|php字符转二进制|php二进制字符转换的内容,更多相关内容请关注PHP中文网(www.php.cn)!