史萊姆論壇

史萊姆論壇 (http://forum.slime.com.tw/)
-   論壇程式討論區 (http://forum.slime.com.tw/f79.html)
-   -   主題過長自動截短的修改 (http://forum.slime.com.tw/thread151912.html)

貝斯特 2005-06-21 02:35 PM

主題過長自動截短的修改
 
透過一個簡單的修改,讓論壇發表的主題過長時自動截短,
這個修改只是利用了substr的函數應用而已。

修改forumdisplay.php,搜尋:

PHP代碼:
// build thread data
$thread = process_thread_array($thread, $lastread, $foruminfo['allowicons']);


在下面插入以下程式碼:

PHP代碼:
//===========================================================================================
// Begin truncate option for forumdisplay.
//===========================================================================================
if (strlen($thread['threadtitle'])>10)
{
$thread['threadtitle'] = substr($thread['threadtitle'],0,10)."...";
}
//===========================================================================================


這樣便修改完成了,請注意這段程式碼:

PHP代碼:
$thread['threadtitle'] = substr($thread['threadtitle'],0,10)."...";


裡面的10是預設顯示的字數,超過則以...取代,當然你可以依照自己的喜好修改這個數值。

貝斯特 2005-06-21 02:37 PM

[vBulletin]若伺服器不支援MB函數,可以將以下程式碼套用到程式中
 
語法:

<?php
//////////////////////////////////////////////////////////////////////
//程式作者:Sky                                                            //
//程式出處:http://940.cc、http://sktw.com                      //
//作者信箱:tw34cc@yahoo.com.tw                                  //
//此程式僅供研究修正用,若有任何錯誤,本人將不負任何責任。        //
//程式功用:於網頁空間上,解決不支援 php_mbstring.dll的問題。  //
/////////////////////////////////////////////////////////////////////
//mb_strlen()
//說明 string mb_strlen ( string str [, string encoding] )
function mb_strlen($text,$encode='big5'){
    if (ini_get("magic_quotes_gpc")){
        $text = StripSlashes($text);
    }
    switch($encode){
        case "big5":
            $a=strlen($text);
            for ($i=0; $i<$a; $i++){
                $ck=ord(substr($text,$i,1));
                if ($ck>127){
                    $i++;
                    $len+=1;
                } else {
                    $len+=1;
                }
            }
            break;
        default:
            $len=false;
            break;
    }
    return $len;
}
//mb_substr()
//說明 string mb_substr ( string str, int start [, int length [, string encoding]] )
//
function mb_substr($text,$str,$length,$encode='big5'){
    if (ini_get("magic_quotes_gpc")){
        $text = StripSlashes($text);
    }
    switch($encode){
        case "big5":
            $a=strlen($text);
            if (empty($length)){
                $length=mb_strlen($text,$encode);
            }
            for ($i=0; $i<$a; $i++){
                $j='';
                $ck=ord(substr($text,$i,1));
                if ($ck>127){
                    $j=$i;
                    $i++;
                    if ($len>=$str && $cks<$length){
                        $word.=substr($text,$j,2);
                        $cks+=1;
                    }
                    $len+=1;
                } else {
                    if ($len>=$str && $cks<$length){
                        $word.=substr($text,$i,1);
                        $cks+=1;
                    }
                    $len+=1;
                }
            }
            break;
        default:
            $len=false;
            break;
    }
    return $word;
}
?>

在下面插入以下程式碼:


PHP代碼:
//===========================================================================================
// Begin truncate option for forumdisplay.
//===========================================================================================
if (mb_strlen($thread['threadtitle'],big5)>10)
{
$thread['threadtitle'] = mb_substr($thread['threadtitle'],0,10,big5)."...";
}
//===========================================================================================




這樣便修改完成了,請注意這段程式碼:


PHP代碼:
$thread['threadtitle'] = mb_substr($thread['threadtitle'],0,10,big5)."...";




裡面的10是預設顯示的字數,超過則以...取代,當然你可以依照自己的喜好修改這個


所有時間均為台北時間。現在的時間是 06:55 PM

Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2025, Jelsoft Enterprises Ltd.

『服務條款』

* 有問題不知道該怎麼解決嗎?請聯絡本站的系統管理員 *


SEO by vBSEO 3.6.1