酷!學園
技術討論區 => 程式討論版 => PHP程式設計討論區 => 主題作者是: phy2001 於 2002-09-19 17:10
-
詳細問題內容:
datebase : hotani
資料表 : articles
欄位 :
欄位 型態 屬性 Null 預設值 附加
article_id int(10) UNSIGNED 否 auto_increment
user_id int(10) 是 NULL
periodical_id int(10) 是 NULL
date_posted datetime 是 NULL
title varchar(100) 是 NULL
body text 是 NULL
img varchar(100) 是 NULL
如何在php中用select body(內文)。
只選取前面十個字~~~~
像 元智資訊傳播學系中的公告事項
http://140.138.146.3/index.asp
-
試試看
$body=htmlspecialchars(substr($body,0,19))."...........";
擷取 body 從 0 到 19 共 20 個字元後面加上 ..........
例如
echo $body ;
顯示
12345678901234567890.........
必須注意一下中英文混合時,最後一個中文字會被擷取一半變亂碼
-
謝謝 ahtry 大大的幫忙,
小弟成功試出來了,
謝謝 ahtry ~~~~~
-
必須注意一下中英文混合時,最後一個中文字會被擷取一半變亂碼
遇到中文也不會出槌的方式
$ct=10;
if(strlen($body) > $ct) {
for($wr=0;$wr<$ct;$wr++) {
$ch=substr($body,$wr,1);
if(ord($ch)>127) $wr++;
}
$body= substr($body,0,$wr);
}