php 中ASCII编码的使用

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

1.chr()函数 
该函数用于将ASCII码值转化为字符串。其函数声明如下: 
string chr (int ascii); 
2.ord()函数
该函数用于将字符串转化为ASCII码值。其函数声明如下: 
int ord(string str);

截取UTF-8字符串。

function utf8_substr($str, $limit) { 
	$restr = ''; 
	for($i=0;$i< $limit-3;$i++) { 
		$restr .= ord($str[$i])>127 ? $str[$i].$str[++$i].$str[++$i] : $str[$i]; 
	}
	return $restr; 
}
原文地址:https://www.cnblogs.com/wyzs/p/5197934.html