RSS| 首页| 山顶道| 布珞阁¹| GoodUI| 土产| 关于

php4下兼容问题解决
2009.06.24 19:16 bruce:

随手写的php程序,用到了一些高级方法。

在php4上一装问题百出,解决办法这里记录一下,以下代码

1:用到了字符串不区分大小写比较 stripos,采用模拟实现

if(!function_exists("stripos")) { function stripos($str,$needle,$offset=0) { return strpos(strtolower($str),strtolower($needle),$offset); } }
if(!function_exists("strripos")) { function strripos($haystack,$needle,$offset=0) { if(!is_string($needle))$needle=chr(intval($needle)); if($offset<0) { $temp_cut=strrev(substr($haystack,0,abs($offset))); } else { $temp_cut=strrev(substr($haystack,0,max((strlen($haystack)-$offset),0))); } if(($found=stripos($temp_cut,strrev($needle)))===false)return false; $pos=(strlen($haystack)-($found+$offset+strlen($needle))); return $pos; } }

2.用到了mb_strlen()函数计算UTF-8支付长度,采用模拟实现

if ( !function_exists('mb_strlen') ) {
function mb_strlen ($text,   $encode) {
 if ($encode=='UTF-8') {
 return preg_match_all('%(?:
 [\x09\x0A\x0D\x20-\x7E]             # ASCII
 |   [\xC2-\xDF][\x80-\xBF]              # non-overlong 2-byte
 |   \xE0[\xA0-\xBF][\x80-\xBF]       # excluding   overlongs
 |   [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight   3-byte
 |   \xED[\x80-\x9F][\x80-\xBF]       # excluding   surrogates
 |   \xF0[\x90-\xBF][\x80-\xBF]{2}    # planes   1-3
 |   [\xF1-\xF3][\x80-\xBF]{3}         #   planes 4-15
 |   \xF4[\x80-\x8F][\x80-\xBF]{2}    # plane   16
 )%xs',$text,$out);
 }else{
 return strlen($text);
 }
}

3.用到iconv转换编码,GBK<->UTF8,结果安装php4时没带参数,只能重新配置php4,安装

用phpinfo()找到以前的配置参数。然后用以前的安装版本重新配置

# ./configure  ……  —-with-iconv
# make
# make install

装上后,在phpinfo()页面可以看到iconv的信息

分类  日经| 暂无评论


垃圾太厉害了
说几句吧






*注意: 回复可能需要审查.您不必重复提交.