1、addcslashes
要向字符串中的特定字符添加反斜杠
<?php header('Content-type:text/html;charset=utf8'); $str='are you ok ???'; echo addcslashes($str,'a..z'); //注意中间是两个点,如果要指定多个字符,那么可以单列出来,如 addcslashes($str,'abr'); //返回值是 \a\r\e \y\o\u \o\k ??? ?>
2、addslashes
在特定的字符前加上反斜线。这些字符是单引号,双引号,反斜线与NULL。
<?php header('Content-type:text/html;charset=utf8'); $str='are "you" ok \???'; echo addslashes($str); //返回值是 are \"you\" ok \\??? ?>
3、bin2hex与hex2bin函数
bin2hex:表示把ASCII码字符的字符串转成十六进制
hex2bin:是对bin2hex函数的反转
<?php header('Content-type:text/html;charset=utf8'); $str = 'are you ok ???'; $code = bin2hex($str); echo $code; //输出 61726520796f75206f6b203f3f3f echo '<br>'; echo hex2bin($code); //输出 are you ok ??? ?>
4、chunk_split
chunk_split(string,length,end)
string=>表示需要分割的字符串
length=>表示分割的长度
end=>表示分割后的结尾字符串
<?php header('Content-type:text/html;charset=utf8'); $str = 'are you ok ???'; echo chunk_split($str,10,'__'); //如果最后一个不够,那么end最加在最后一位上 //输出结果 are you ok__ ???__ 注意本函数不改变原有的字符串 ?>
5、convert_uuencode与convert_uudecode函数
表示对指定的字符串进行编码以及解码,返回编码或解码后的字符串,如果失败,那么返回false
<?php header('Content-type:text/html;charset=utf8'); $str = 'are you ok ???'; $exa = convert_uuencode($str); echo $exa; //输出值为 .87)E('EO=2!O:R`_/S\` ` echo '<br>'; echo convert_uudecode($exa); //输出值为 are you ok ??? ?>