作者appleboy46 (小惡魔)
看板PHP
標題Re: [請益] 怎樣讓表格欄位的高度固定
時間Sat Mar 28 15:00:47 2009
※ 引述《nomoty (朋友??)》之銘言:
: 我有一個表格欄位是接收使用者輸入的值,但輸入值
: 的大小並不是固定的,因此當輸入的字多的時候,欄
: 位高度就變的很大
: 以下是我欄位的程式碼
: <td style="word-wrap:break-word;word-break:break-all;"width="200" height="50" > <font face="標楷體"><?php echo
: $row_f1['content']; ?></font></td>
: 已經將欄位寬度設定為固定大小自動換行,但要怎樣能讓欄位只顯示符合大小,
: 其他多餘的字就隱藏
原文:
http://blog.wu-boy.com/2007/05/18/104/
適用於 Big5:
function cut_word($text, $num){
if(strlen($text) > $num) {
for($i=0;$i<$num;$i++) {
$ch=substr($text,$i,1);
if(ord($ch)>127) $i++;
}
$text= substr($text,0,$i).".";
}
return $text;
}
用於 UTF-8 跟 Big5
function bite_str($string, $start, $len, $byte=3)
{
$str = "";
$count = 0;
$str_len = strlen($string);
for ($i=0; $i<$str_len; $i++) {
if (($count+1-$start)>$len) {
$str .= "...";
break;
} elseif ((ord(substr($string,$i,1)) <= 128) && ($count < $start)) {
$count++;
} elseif ((ord(substr($string,$i,1)) > 128) && ($count < $start)) {
$count = $count+2;
$i = $i+$byte-1;
} elseif ((ord(substr($string,$i,1)) <= 128) && ($count >= $start)) {
$str .= substr($string,$i,1);
$count++;
} elseif ((ord(substr($string,$i,1)) > 128) && ($count >= $start)) {
$str .= substr($string,$i,$byte);
$count = $count+2;
$i = $i+$byte-1;
}
}
return $str;
}
或者利用:mb_substr 都可以
--
Appleboy Blog:
http://blog.Wu-Boy.com 電腦技術、美食介紹、旅遊資訊
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 219.69.81.52
推 nomoty :感謝...剛有試了一下,不過用bite_str欄位裡面是中文 03/28 22:17
→ nomoty :會無法顯示字出來,mb_substr則是正常 03/28 22:17
→ appleboy46 :bite_str 這是可以用的喔,麻煩寫一下程式碼 03/28 22:41