php将字符串进行ASCII升序排列

编程入门 行业动态 更新时间:2024-10-10 11:27:55

php将字符串进行ASCII<a href=https://www.elefans.com/category/jswz/34/1745629.html style=升序排列"/>

php将字符串进行ASCII升序排列

方法一:

$str = '';
$ascll = unpack("C*",$str);
sort($ascll);
$data = implode(',',$ascll);
$asclla =pack("C*",48,49,50);

方法二:

for($i=0;$i<strlen($str);$i++){$temp_str=ord($str[$i]);$change_after[$i] = $temp_str;
}sort($change_after);$str = '';for($i=0;$i<count($change_after);$i++){$str .=chr($change_after[$i]);}

方法三

$arr = str_split($str);
asort($arr);
$str=implode('',$arr);

php将字符串转为ASCII,php将中文汉字字符串转为ASCII

public function strtoascii($str){$str=mb_convert_encoding($str,'GB2312');$change_after='';for($i=0;$i<strlen($str);$i++){$temp_str=dechex(ord($str[$i]));$change_after.=$temp_str[1].$temp_str[0];}return strtoupper($change_after);
}public function asciitostr($sacii){$asc_arr= str_split(strtolower($sacii),2);$str='';for($i=0;$i<count($asc_arr);$i++){$str.=chr(hexdec($asc_arr[$i][1].$asc_arr[$i][0]));}return mb_convert_encoding($str,'UTF-8','GB2312');
}

注意:如果是中文,php文件环境是UTF-8,GBK不需要mb_convert_encoding操作

更多推荐

php将字符串进行ASCII升序排列

本文发布于:2024-02-19 19:42:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1765442.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:升序   字符串   排列   php   ASCII

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!