散分,支持多种编码的中文字符串截取函数! $length必须输入吗?截取前怎么知道$length呢?没搞清楚这个函数的用途…… 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 to snmr_com(麒麟厍人) 请看清标题:中文字符串,我没有把每个字符集都包含进去,因为没那个必要,我们主要就是针对中文,除非有特殊需要,可以改一下,length是你要截取的长度,截取字符串的函数不都这几个参数? /* * @todo 中文截取,支持gb2312,gbk,utf-8,big5 * * @param string $str 要截取的字串 * @param int $start 截取起始位置 * @param int $length 截取长度 * @param string $charset utf-8|gb2312|gbk|big5 编码 * @param $suffix 是否加尾缀 */ 还差BIG5-HKSCS能也补上吗? 我也发布一个吧,SMS对纯ACSII用7BIT压缩后再传送。这个是函数实现解压功能。function Decode7bit($str7bit){ for ($i=0; $i<strlen($str7bit);$i+=2) { $str = decbin(hexdec($str7bit[$i].$str7bit[$i+1])); $arrBin[] = sprintf("%08s", $str); } //print_r($arrBin); $i=0; $move =1; while ($i<count($arrBin)) { if ($i==0) { $dst = substr($arrBin[$i],$move); }elseif ($i%7==0 && $i!=0) { //special char switch ($left) { case '0000000': $left = '1000000'; break; } $arrBinDst[] =$left; $strDst .=chr(bindec($left)); $move=1; $left=''; } $dst = substr($arrBin[$i],$move).$left; $left =substr($arrBin[$i],0,$move); $move++; $i++; //special char switch ($dst) { case '0000000': $dst = '1000000'; break; } $arrBinDst[]=$dst; $strDst .=chr(bindec($dst)); } //print_r($arrBinDst); return $strDst; } $re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";可简化为$re['utf-8'] = "/[\x00-\x7f]|[\xc0-\xff][\x80-\xbf]+/"; 高手都在这儿.我顺便在这儿问一个问题为什么我的apache(2.0.58)用SAPI模块,即LoadModule php5_module "c:/php/php5apache2.dll"AddType application/x-httpd-php .php这样的配置就行.用CGI模块,即ScriptAlias /php/ "C:/php"AddType application/x-httpd-php .php# For PHP 5Action application/x-httpd-php "/php/php-cgi.exe"怎么就不能解析PHP了呢? 请给推荐一本php入门书,没编程基础,只会html代码。谢谢。 菜鸟跪求高手解决图片上传的问题 PHP下载问题 select max(id)问题? 小问题,请大侠指点 这个双循环出不来了,不知道为什么无法显示 丢死人了,真是出师不利! 请问?form中的数据提交后,后一页为什么接受不到数据呢? 一个让人想破头也想不出来的问题 请教高手们这个PHP代码是哪里错误 关于那个用PHP的fsockopen写的HTTP的下载类 include 比 include_once 快吗?
请看清标题:中文字符串,我没有把每个字符集都包含进去,因为没那个必要,我们主要就是针对中文,除非有特殊需要,可以改一下,
length是你要截取的长度,截取字符串的函数不都这几个参数?
* @todo 中文截取,支持gb2312,gbk,utf-8,big5
*
* @param string $str 要截取的字串
* @param int $start 截取起始位置
* @param int $length 截取长度
* @param string $charset utf-8|gb2312|gbk|big5 编码
* @param $suffix 是否加尾缀
*/
能也补上吗?
这个是函数实现解压功能。
function Decode7bit($str7bit)
{
for ($i=0; $i<strlen($str7bit);$i+=2)
{
$str = decbin(hexdec($str7bit[$i].$str7bit[$i+1]));
$arrBin[] = sprintf("%08s", $str);
}
//print_r($arrBin);
$i=0;
$move =1;
while ($i<count($arrBin)) {
if ($i==0) {
$dst = substr($arrBin[$i],$move);
}elseif ($i%7==0 && $i!=0) {
//special char
switch ($left)
{
case '0000000':
$left = '1000000';
break;
}
$arrBinDst[] =$left;
$strDst .=chr(bindec($left));
$move=1;
$left='';
}
$dst = substr($arrBin[$i],$move).$left;
$left =substr($arrBin[$i],0,$move);
$move++;
$i++;
//special char
switch ($dst)
{
case '0000000':
$dst = '1000000';
break;
}
$arrBinDst[]=$dst;
$strDst .=chr(bindec($dst));
}
//print_r($arrBinDst);
return $strDst;
}
可简化为
$re['utf-8'] = "/[\x00-\x7f]|[\xc0-\xff][\x80-\xbf]+/";
为什么我的apache(2.0.58)
用SAPI模块,即
LoadModule php5_module "c:/php/php5apache2.dll"
AddType application/x-httpd-php .php
这样的配置就行.用CGI模块,即
ScriptAlias /php/ "C:/php"
AddType application/x-httpd-php .php
# For PHP 5
Action application/x-httpd-php "/php/php-cgi.exe"
怎么就不能解析PHP了呢?