PHP ord()函数与示例
PHPord()方法
ord()函数是一个字符串函数,用于获取给定字符串第一个字符的ASCII码。
语法:
ord(string);
它接受字符串并返回数字值(ASCII码)。
例子:
Input: "Abc"
Output: 65PHP代码:
<?php
$str = "Abc";
echo ("ASCII code of first character is = " . ord($str) . "\n");
$str = "Hello world";
echo ("ASCII code of first character is = " . ord($str) . "\n");
$str = "_okay";
echo ("ASCII code of first character is = " . ord($str) . "\n");
$str = "123Hello";
echo ("ASCII code of first character is = " . ord($str) . "\n");
?>输出结果
ASCII code of first character is = 65 ASCII code of first character is = 72 ASCII code of first character is = 95 ASCII code of first character is = 49