Home  >  Article  >  php教程  >  php二进制输出|php字符转二进制|php二进制字符转换

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

PHP中文网
PHP中文网Original
2016-05-22 17:22:191301browse

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)!

     

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn