`
piperzero
  • 浏览: 3471563 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

php函数:chr & ord

 
阅读更多

chr

string chr ( int $ascii )

返回相对应于 ascii所指定的单个字符。

例子

<?php
$str = "The string ends in escape: ";
$str .= chr(27); /* 在 $str 后边增加换码符 */

/* 通常这样更有用 */

$str = sprintf("The string ends in escape: %c", 27);
?>

ord

int ord ( string $string )

返回字符串 string 第一个字符的 ASCII 码值。

例子

<?php
$str = "\n";
if (ord($str) == 10) {
    echo "The first character of \$str is a line feed.\n";
}
?>


可以在此处找到 ASCII 码表:» http://www.asciitable.com

chr()与ord() 是互补的。参见 sprintf() 如何使用格式字符串 %c


ASCII 码表



分享到:
评论

相关推荐

    php的chr和ord函数实现字符加减乘除运算实现代码

    chr函数用于将ASCII码转换为字符 ord函数是用来字符转换为ASCII码 ASCII码是计算机所能显示字符的编码,它的取值范围是0-255,其中包括标点、字母、数字、汉字等。在编程过程中,经常把指定的字符转化为ASCII码进行...

    PHP函数篇之掌握ord()与chr()函数应用

    ord()函数把字符转换为十进制数字,chr()函数把十进制数字转化为字符,在二进制,八进制,十进制与十六进制之间充当桥梁的作用

    浅谈Python中chr、unichr、ord字符函数之间的对比

    chr、unichr、ord在Python中都可以被用作字符类型转换,这里我们就来浅谈Python中chr、unichr、ord字符函数之间的对比,需要的朋友可以参考下

    PHP实现字符串大小写转函数的功能实例

    字符串的大小写转换功能在日常中经常使用。...return $ord&gt;=97 && $ord&lt;=122 ?chr($ord-32):$c;}//字符转小写protected function tolower($c){ $ord = ord($c); return $ord&gt;=65 && $ord&lt;=90 ?chr($ord

    如何使用PHP中的字符串函数

    (3)Chr,Ord 类似于C的同名函数. (4)explode,implode,join 这些是和数组有关的函数. explode(字符串,分割符)返回一个将字符串在分割符处分开所产生的数组. implode(数组,分割符)返回一个将数组各元素之间插上...

    php2go:使用Golang来实现PHP的常见内置函数

    PHP函数 日期/时间功能 time() strtotime() date () checkdate () sleep () usleep () 字符串函数 strpos() stripos() strrpos () strripos () str_replace () ucfirst () lcfirst () ucwords () substr () strrev ...

    php 获得汉字拼音首字母的函数

    php function getinitial($str) { $asc=ord(substr($str,0,1)); if ($asc&lt;160&gt;=48 && $asc&lt;=57){ return ‘1’; //数字 }elseif ($asc&gt;=65 && $asc&lt;=90){ return chr($asc); // A–Z }elseif ($asc&gt;=97 && $...

    PHP基础教程HTML版本

    (3)Chr,Ord 类似于C的同名函数. (4)explode,implode,join 这些是和数组有关的函数. explode(字符串,分割符)返回一个将字符串在分割符处分开所产生的数组. implode(数组,分割符)返回一个将数组各元素之间插上分割符...

Global site tag (gtag.js) - Google Analytics