Notice: Uninitialized string offset: 18 in D:\EasyPHP-12.1\www\include\deal_string.php on line 17Notice: Uninitialized string offset: 18 in D:\EasyPHP-12.1\www\include\deal_string.php on line 22应该是 $chars[$i])){// 这里出了什么问题.求详细解答.从来没接触过PHP..<?php
/*
取得所設定的字串長度,若字串超過所設定的長度,則在字串的後面加上"‧‧‧"
$string:要計算字數的字數
$start:開始計算的字元位置
$length:設定要取的字串長度*/
function substr_utf8($string,$start,$length)
{
$chars = $string;
$f=0;
$i=0;
$m=0;
$n=0;
do{
if (preg_match ("/[0-9a-zA-Z]/", $chars[$i])){//?英文
$m++;
}else {$n++; //非英文字?,
}
if ($chars[$i]<>"")//如果不是空的字元,加總累計
$f++;
$k = $n/3+$m/2;
$l = $n/3+$m;//最?截取?度;$l = $n/3+$m*2?
$i++;
} while($k < $length);
$str1 = mb_substr($string,$start,$l,'utf-8');//保?不?出???
if ($f>($length*3-10))//如果中文字超過設定的長度,則在字串的最後面加上.....
$str1=$str1."...";
return $str1;
}?>
/*
取得所設定的字串長度,若字串超過所設定的長度,則在字串的後面加上"‧‧‧"
$string:要計算字數的字數
$start:開始計算的字元位置
$length:設定要取的字串長度*/
function substr_utf8($string,$start,$length)
{
$chars = $string;
$f=0;
$i=0;
$m=0;
$n=0;
do{
if (preg_match ("/[0-9a-zA-Z]/", $chars[$i])){//?英文
$m++;
}else {$n++; //非英文字?,
}
if ($chars[$i]<>"")//如果不是空的字元,加總累計
$f++;
$k = $n/3+$m/2;
$l = $n/3+$m;//最?截取?度;$l = $n/3+$m*2?
$i++;
} while($k < $length);
$str1 = mb_substr($string,$start,$l,'utf-8');//保?不?出???
if ($f>($length*3-10))//如果中文字超過設定的長度,則在字串的最後面加上.....
$str1=$str1."...";
return $str1;
}?>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货