首頁 >php教程 >PHP源码 >php二进制输出|php字符转二进制|php二进制字符转换

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

PHP中文网
PHP中文网原創
2016-05-22 17:22:191363瀏覽

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

<?php
header(&#39;Content-type:text/html; charset=utf-8&#39;);

class binaryString{
	
	protected $split = &#39;&&#39;;
	
	public function bin2str($bin, $str = &#39;&#39;){
		$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(&#39;这是字符转二进制输出的示例&#39;);

echo $b->bin2str($s);

             

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

     

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn