1. 擷取gb2312中文字串
<?php
< ?
php//擷取中文字串
function
mysubstr
($str
, $start
, $len
)else
$tmpstr
.= substr
($str
, $i, 1
);}return
$tmpstr;}
?>
2. 擷取utf8編碼的多位元組字串
<?php
< ?
php//擷取utf8字串
function
utf8substr
($str
, $from
, $len)'
.'((?:[/x00-/x7f]|[/xc0-/xff][/x80-/xbf]+)).*#s',
'$1',
$str);
}?>
3. utf-8、gb2312都支援的漢字擷取函式
<?php
< ?
php/*
utf-8、gb2312都支援的漢字擷取函式
cut_str(字串, 擷取長度, 開始長度, 編碼);
編碼預設為 utf-8
開始長度預設為 0
*/function
cut_str
($string
, $sublen
, $start= 0
, $code= '
utf-8')
else
else}if
(ord
(substr
($string
, $i, 1
))>
129)
$i++; }if
(strlen
($tmpstr
)<
$strlen
)$tmpstr
.= "
..."
; return
$tmpstr; }
}$str= "
abcd需要擷取的字串";
echo
cut_str
($str, 8
, 0, '
gb2312')
; ?>
4. bugfree 的字元擷取函式
<?php
< ?
php/**
*@package
bugfree
*@version
$id: function**ain.inc.php,v 1.32 2005/09/24 11:38:37 wwccss exp $
* *
* return part of a string(enhance the function substr()) * *
@author
chunsheng wang <
>
*@param
string $string the string to cut.
*@param
int $length the length of returned string.
*@param
@return
string the cutted string.
*/function
syssubstr
($string
,$length,=
false
)else
elseif
(ord
($stringtmp
)>=
192)
else
$stringlast
= $stringtmp; }
$stringlast
= implode(""
,$stringlast);
if()return
$stringlast; }
}$string= "
codebit.cn -- 簡單、精彩、通用";
$length= "
18"; =
false
; echo
syssubstr
($string
,$length,)
; ?>
PHP 擷取字串專題
php 擷取字串專題 1.擷取gb2312中文字串 擷取中文字串 function mysubstr str,start,len else tmpstr substr str,i,1 return tmpstr 2.擷取utf8編碼的多位元組字串 擷取utf8字串 function utf8subs...
PHP 擷取字串專題
url 1.擷取gb2312中文字串 php 擷取中文字串 function mysubstr str,start,len else tmpstr substr str,i,1 return tmpstr 2.擷取utf8編碼的多位元組字串 擷取utf8字串 function utf8substr ...
PHP 擷取字串專題
1.擷取gb2312中文字串 php 擷取中文字串 function mysubstr str,start,len else tmpstr substr str,i,1 return tmpstr 2.擷取utf8編碼的多位元組字串 php 擷取utf8字串 function utf8substr ...