/////////////////////////////////////////////////
// PukiWiki - Yet another WikiWikiWeb clone.
//
-// $Id: mbstring.php,v 1.3 2003/07/05 05:18:06 arino Exp $
+// $Id: mbstring.php,v 1.4 2003/07/08 07:03:03 arino Exp $
//
/*
* PHP¤Îmbstring extension¤¬»ÈÍѤǤ¤Ê¤¤¤È¤¤ÎÂåÂشؿô
*
+ * Ãí°Õ»ö¹à
+ *
+ * EUC-JPÀìÍѤǤ¹¡£
+ *
* »ÈÍÑÊýË¡
*
* jcode_1.34.zip (http://www.spencernetwork.org/)¤òÆþ¼ê¤·¤Æ¡¢
// mb_strimwidth -- »ØÄꤷ¤¿Éý¤Çʸ»úÎó¤ò´Ý¤á¤ë
function mb_strimwidth($str,$start,$width,$trimmarker='',$encoding='')
{
- $substr = mb_substr($str,$start,$width);
- if (strlen($str) > strlen($substr))
+ if ($start == 0 and $width <= strlen($str))
+ {
+ return $str;
+ }
+
+ // Ãí: EUC-JPÀìÍÑ, $encoding¤ò»ÈÍѤ·¤Ê¤¤
+ $chars = unpack('C*', $str);
+ $substr = '';
+
+ while (count($chars) and $start > 0)
+ {
+ $start--;
+ if (array_shift($chars) >= 0x80)
+ {
+ array_shift($chars);
+ }
+ }
+ if ($b_trimmarker = (count($chars) > $width))
+ {
+ $width -= strlen($trimmarker);
+ }
+ while (count($chars) and $width-- > 0)
+ {
+ $char = array_shift($chars);
+ if ($char >= 0x80)
+ {
+ if ($width-- == 0)
+ {
+ break;
+ }
+ $substr .= chr($char);
+ $char = array_shift($chars);
+ }
+ $substr .= chr($char);
+ }
+ if ($b_trimmarker)
{
- // Ãí: ËÜÍè¤Ïstrlen($substr.$trimmarker) == $width¤È¤Ê¤ë¤Ù¤
$substr .= $trimmarker;
}
return $substr;
// mb_strlen -- ʸ»úÎó¤ÎŤµ¤òÆÀ¤ë
function mb_strlen($str,$encoding='')
{
- // Ãí: $encoding¤ò»ÈÍѤ·¤Ê¤¤
+ // Ãí: EUC-JPÀìÍÑ, $encoding¤ò»ÈÍѤ·¤Ê¤¤
return jstrlen($str);
}
// mb_substr -- ʸ»úÎó¤Î°ìÉô¤òÆÀ¤ë
function mb_substr($str,$start,$length=0,$encoding='')
{
- // Ãí: $encoding¤ò»ÈÍѤ·¤Ê¤¤
+ // Ãí: EUC-JPÀìÍÑ, $encoding¤ò»ÈÍѤ·¤Ê¤¤
return jsubstr($str,$start,$length);
}
?>