/**
* [字符串转换为(2,8,16进制)ASCII码]
* @param string $str [待处理字符串]
* @param boolean $encode [字符串转换为ASCII|ASCII转换为字符串]
* @param string $intType [2,8,16进制标示]
* @return string byte_str [处理结果]
* @author alexander
*/
function strtoascii($str, $encode=true, $intType="2"){
if($encode == true){
$byte_array = str_split($str);
foreach($byte_array as &$value){
$value = ord($value);
switch ($intType) {
case 16:
$value = sprintf("x", $value);
break;
case 8:
$value = sprintf("o", $value);
break;
default:
$value = sprintf("b", $value);
break;
}
}
unset($value);
$byte_str = implode('', $byte_array);
}
else{
$chunk_size = $intType == 16 ? 2 : ($intType == 8 ? 3 : 8);
$byte_array = chunk_split($str, $chunk_size);
$byte_array = array_filter(explode("\r\n", $byte_array));
foreach($byte_array as &$value){
$fun_name = $intType == 16 ? 'hexdec' : ($intType == 8 ? 'octdec' : 'bindec');
$value = $fun_name($value);
$value = chr($value);
}
unset($value);
$byte_str = implode('', $byte_array);
}
return $byte_str;
}
| [url=http://php.net/manual/zh/function.bindec.php]bindec[/url] | 二进制转换为十进制 |
| [url=http://php.net/manual/zh/function.decbin.php]decbin[/url] | 十进制转换为二进制 |
| [url=http://php.net/manual/zh/function.octdec.php]octdec[/url] | 八进制转换为十进制 |
| [url=http://php.net/manual/zh/function.decoct.php]decoct[/url] | 十进制转换为八进制 |
| [url=http://php.net/manual/zh/function.hexdec.php]hexdec[/url] | 十六进制转换为十进制 |
| [url=http://php.net/manual/zh/function.dechex.php]dechex[/url] | 十进制转换为十六进制 |
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有