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

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

PHP中文网
Release: 2016-05-22 17:22:19
Original
1362 people have browsed it

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);
Copy after login

             

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

     

Related labels:
source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template