Home  >  Article  >  Backend Development  >  大写小写相互转换

大写小写相互转换

WBOY
WBOYOriginal
2016-06-13 11:06:421159browse

大写小写互相转换
现在客户端和服务器端的PHP base64 的编码方式不同
例如服务器端为 aGVsbG8=
那么客户端就是 AgvSBg8= 我怎么才能做到转换大小写?
我现在的做法是遍历每个字节的ASCII码,判断大小,然后决定加减32
------解决方案--------------------

print preg_replace('/([a-z]*)([A-Z]*)/e',"strtolower('\$2').strtoupper('\$1')",$string); 

------解决方案--------------------

本帖最后由 xuzuning 于 2012-11-21 11:18:53 编辑 A    二进制内码表示为 01000001
a    二进制内码表示为 01100001
空格 二进制内码表示为 00100000 

所以字母与空格异或后正好是变换大小写

可见 ASCII 码的创始人是何等的聪明!
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