php 怎么实现vb的chrB函数的功能---100分 PHP也有chr()函数..但没有chrb(),强制转换,将单字符转为单字节,这点PHP容易........ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 php的chr()函数就是vb的chrB()函数 在php中chr()函数的作用和vb里面的chrB()是一样的 php的chr()函数就是vb的chrB()函数! 相反的函数是 ord(string)同 vbs 中的 asc 附上用法例子,一个判断字符串是否由utf-8格式的函数function utf8_probability(&$rawtextstr) {$score = 0;$i = 0;$rawtextlen = 0;$goodbytes = 0;$asciibytes = 0;$rawtextarray = preg_split("//",$rawtextstr,-1, PREG_SPLIT_NO_EMPTY); //转换成char数组,如果是php5,则可使用str_split$rawtext = array();//var_dump($rawtextarray);die;for($i=0;$i<count($rawtextarray);$i++)$rawtext[] = ord($rawtextarray[$i]); //ord(char)// Maybe also use UTF8 Byte Order Mark(BOM): EF BB BF//BOM,某些utf8文件流的首3个字节,可以表示这个文件的编码方式// Check to see if characters fit into acceptable ranges//print_r($rawtext);$rawtextlen = strlen($rawtextstr);for ($i = 0; $i < $rawtextlen; $i++) {if ($rawtext[$i] < 0x80) { // One byte $asciibytes++; // Ignore ASCII, can throw off count} else if (0xC0 <= $rawtext[$i] && $rawtext[$i] <= 0xDF && // Two bytes$i+1 < $rawtextlen && 0x80 <= $rawtext[$i+1] && $rawtext[$i+1] <= 0xBF) {$goodbytes += 2; $i++;} else if (0xE0 <= $rawtext[$i] && $rawtext[$i] <= 0xEF && // Three bytes$i+2 < $rawtextlen && 0x80 <= $rawtext[$i+1] && $rawtext[$i+1] <= 0xBF &&0x80 <= $rawtext[$i+2] && $rawtext[$i+2] <= 0xBF) {$goodbytes += 3; $i+=2;}//if you want check just a few ,you may stop here with a score make.//or you will be delayed when you meet lots of big files.}//ascii is sub of utf8if ($asciibytes == $rawtextlen) { return 0; }$score = (int)(100 * ($goodbytes/($rawtextlen-$asciibytes)));// If not above 98, reduce to zero to prevent coincidental matchesif ($score > 98) {return $score;} else if ($score > 95 && $goodbytes > 30) {// Allows for some (few) bad formed sequencesreturn $score;} else {return 0;}} [提问]PHP 读取 word COM 组件的错误信息 我很是无语啊!!!! 提交数据和查询数据哪个快 如果把cookie禁用掉,session还会不会起作用?【讨论】 求助,php中数组分别提交到不同字段 为什么我在释放记录时总出现这种错误? 我想问怎样才能让页面显示记录时,显示交替的背景颜色呢 jsp中如何调用php?? 我的php什么会把post 过来的变量自动转义? 函数get_class_vars的问题 php的相关问题连接数据库判断条件出现按钮 按下按钮实现页面跳转 如何捕捉warning错误? 关于 https xml 在 php 下传送和接收的问题?
!
同 vbs 中的 asc
$score = 0;
$i = 0;
$rawtextlen = 0;
$goodbytes = 0;
$asciibytes = 0;
$rawtextarray = preg_split("//",$rawtextstr,-1, PREG_SPLIT_NO_EMPTY); //转换成char数组,如果是php5,则可使用str_split
$rawtext = array();//var_dump($rawtextarray);die;for($i=0;$i<count($rawtextarray);$i++)
$rawtext[] = ord($rawtextarray[$i]); //ord(char)
// Maybe also use UTF8 Byte Order Mark(BOM): EF BB BF
//BOM,某些utf8文件流的首3个字节,可以表示这个文件的编码方式// Check to see if characters fit into acceptable ranges
//print_r($rawtext);
$rawtextlen = strlen($rawtextstr);
for ($i = 0; $i < $rawtextlen; $i++) {
if ($rawtext[$i] < 0x80) { // One byte
$asciibytes++; // Ignore ASCII, can throw off count
} else if (0xC0 <= $rawtext[$i] && $rawtext[$i] <= 0xDF && // Two bytes
$i+1 < $rawtextlen && 0x80 <= $rawtext[$i+1] && $rawtext[$i+1] <= 0xBF) {
$goodbytes += 2; $i++;
} else if (0xE0 <= $rawtext[$i] && $rawtext[$i] <= 0xEF && // Three bytes
$i+2 < $rawtextlen && 0x80 <= $rawtext[$i+1] && $rawtext[$i+1] <= 0xBF &&
0x80 <= $rawtext[$i+2] && $rawtext[$i+2] <= 0xBF) {
$goodbytes += 3; $i+=2;
}
//if you want check just a few ,you may stop here with a score make.
//or you will be delayed when you meet lots of big files.
}
//ascii is sub of utf8
if ($asciibytes == $rawtextlen) { return 0; }
$score = (int)(100 * ($goodbytes/($rawtextlen-$asciibytes)));
// If not above 98, reduce to zero to prevent coincidental matches
if ($score > 98) {
return $score;
} else if ($score > 95 && $goodbytes > 30) {
// Allows for some (few) bad formed sequences
return $score;
} else {
return 0;
}
}