ยินดีต้อนรับคุณ, บุคคลทั่วไป กรุณา เข้าสู่ระบบ หรือ ลงทะเบียน

เข้าสู่ระบบด้วยชื่อผู้ใช้ รหัสผ่าน และระยะเวลาในเซสชั่น

ThaiSEOBoard.comพัฒนาเว็บไซต์Programmingเทพ php ซ่อยข่อยแน่ ปรับแต่ง title ไม่ให้เกิน 200 ตัวอักษร
หน้า: [1]   ลงล่าง
พิมพ์
ผู้เขียน หัวข้อ: เทพ php ซ่อยข่อยแน่ ปรับแต่ง title ไม่ให้เกิน 200 ตัวอักษร  (อ่าน 1381 ครั้ง)
0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้
เทพมังกร
Verified Seller
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 37
ออฟไลน์ ออฟไลน์

กระทู้: 1,314



ดูรายละเอียด
« เมื่อ: 17 ตุลาคม 2010, 17:07:51 »

เทพ php ซ่อยข่อยแน่ ปรับแต่ง title ไม่ให้เกิน 200 ตัวอักษร
ผมใ้ช้ php nuke ครับพอดี tile มันดึงเนื้อหาจากคอนเท้น forum มาผมจะปรับแต่งไม่ให้เกิน
200 ตัวอักษร ต้องขอแรงเทพหน่อยครับ

<?php
/********************************************************************/
/* SN Dynamic Titles Addon                                          */ 
/* ===========================                                      */
/* Copyright (c) 2003 by Greg Schoper                               */
/* http://nuke.schoper.net                                           */
/*                                                                  */
/* Based on code from PHP-Nuke                                      */
/* Copyright (c) 2002 by Francisco Burzi                            */
/* http://phpnuke.org                                                */
/*                                                                  */
/* This program is free software. You can redistribute it and/or    */
/* modify it under the terms of the GNU General Public License as   */
/* published by the Free Software Foundation; either version 2 of   */
/* the License.                                                     */
/********************************************************************/
/* Credit to unknown author of original forums code in              */
/* includes/dynamic_titles.php.                                     */
/********************************************************************/
/* Updated for better SEO results using storebuilders suggestions   */
/* sixonetonoffun http://www.netflake.com                            */
/********************************************************************/
if (eregi("dynamic_titles.php",$_SERVER['SCRIPT_NAME'])) {
    Header("Location: index.php");
    die();
}

// Item Delimeter
$item_delim = "";

$newpagetitle = "";

global $name;
include ("config.php");
include("db/db.php");


// Forums
if($name=="Forums"){
global $p,$t,$forum,$f;
$newpagetitle = "$sitename $item_delim $name"; 
$newpagetitle = preg_replace("/\[(\S+)\]/e", "", $newpagetitle);
$newpagetitle = check_html($newpagetitle, nohtml);
    if($p) {
$p = intval($p);
        $sql = "SELECT post_subject, post_id, post_text FROM ".$prefix."_bbposts_text WHERE post_id='$p'";
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $title = $row[post_subject];
        $post = $row[post_id];
        $ptext = $row[post_text];

        $newpagetitle = "$title $item_delim $ptext";
        $newpagetitle = preg_replace("/\[(\S+)\]/e", "", $newpagetitle);
        $newpagetitle = check_html($newpagetitle, nohtml);
    }
    if($t) {
$t = intval($t);
        $sql = "SELECT topic_first_post_id  FROM ".$prefix."_bbtopics WHERE topic_id='$t'";
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $tpid = $row[topic_first_post_id ];
         
        $sql = "SELECT post_subject, post_id, post_text FROM ".$prefix."_bbposts_text WHERE post_id='$tpid'";
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $title = $row[post_subject];
        $post = $row[post_id];
        $ptext = $row[post_text];

        $newpagetitle = "$title $item_delim $ptext";
        $newpagetitle = preg_replace("/\[(\S+)\]/e", "", $newpagetitle);
        $newpagetitle = check_html($newpagetitle, nohtml);
    }
    elseif($f) {
$f = intval($f);
        $sql = "SELECT forum_name FROM ".$prefix."_bbforums WHERE forum_id='$f'";
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $forum = $row[forum_name];
        $newpagetitle = "$sitename $item_delim $forum";
        $newpagetitle = preg_replace("/\[(\S+)\]/e", "", $newpagetitle);
        $newpagetitle = check_html($newpagetitle, nohtml);
    }
}

// News
if($name=="News"){
global $file,$sid,$new_topic, $slogan;
$newpagetitle= "$sitename $item_delim $slogan $item_delim $name";
$newpagetitle = check_html($newpagetitle, nohtml);
    if ($new_topic!=""){
       $sql = "SELECT topictext FROM ".$prefix."_topics WHERE topicid='$new_topic'";
      $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $top = $row[topictext];
        $newpagetitle= "$top";
        $newpagetitle = check_html($newpagetitle, nohtml);
   }
    if ($file=="article"){
       $sql = "SELECT title, topic FROM ".$prefix."_stories WHERE sid='$sid'";
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $art = $row[title];
        $top = $row[topic];
      $sql = "SELECT topictext FROM ".$prefix."_topics WHERE topicid='$top'";
      $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $top = $row[topictext];
        $newpagetitle= "$top $item_delim $art";
        $newpagetitle = check_html($newpagetitle, nohtml);
    }
}

// Topics
if($name=="Topics"){
$newpagetitle = ""._ACTIVETOPICS."";
$newpagetitle = check_html($newpagetitle, nohtml);
}

// Downloads
if($name=="Downloads"){
global $d_op,$cid,$lid;
$newpagetitle = "$sitename $item_delim $name";
$newpagetitle = check_html($newpagetitle, nohtml);
    if($d_op=="viewdownload") {
        $sql = "SELECT title, parentid FROM ".$prefix."_downloads_categories WHERE cid='$cid'";
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $cat = $row[title];
        $parent = $row[parentid];
            if($parent=="0"){
                $newpagetitle = "$cat";
                $newpagetitle = check_html($newpagetitle, nohtml);
            }
            else{
                $sql = "SELECT title FROM ".$prefix."_downloads_categories WHERE cid='$parent'";
                $result = $db->sql_query($sql);
                $row = $db->sql_fetchrow($result);
                $parent = $row[title];
                $newpagetitle = "$parent $item_delim $cat";
                $newpagetitle = check_html($newpagetitle, nohtml);
            }
    }
   if($d_op=="viewdownloaddetails" || $d_op=="getit") {
       $sql = "SELECT title FROM ".$prefix."_downloads_downloads WHERE lid='$lid'";
      $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
      $dl = $row[title];
      $newpagetitle = "$dl";
                $newpagetitle = check_html($newpagetitle, nohtml);
   }
}

// Web Links
if($name=="Web_Links"){
global $l_op,$cid,$lid;
$name=ereg_replace("_", " ", "$name");
$newpagetitle = "$name";
$newpagetitle = check_html($newpagetitle, nohtml);
    if($l_op=="viewlink") {
        $sql = "SELECT title, parentid FROM ".$prefix."_links_categories WHERE cid='$cid'";
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $cat = $row[title];
        $parent = $row[parentid];
            if($parent=="0"){
                $newpagetitle = "$cat";
$newpagetitle = check_html($newpagetitle, nohtml);
            }
            else{
                $sql = "SELECT title FROM ".$prefix."_links_categories WHERE cid='$parent'";
                $result = $db->sql_query($sql);
                $row = $db->sql_fetchrow($result);
                $parent = $row[title];
                $newpagetitle = "$parent $item_delim $cat";
$newpagetitle = check_html($newpagetitle, nohtml);
            }
    }
}

// Content
if($name=="Content"){
global $pa,$cid,$pid;
$newpagetitle = "$name";
$newpagetitle = check_html($newpagetitle, nohtml);
    if($pa=="list_pages_categories") {
        $sql = "SELECT title FROM ".$prefix."_pages_categories WHERE cid='$cid'";
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $cat = $row[title];
        $newpagetitle = "$cat";
$newpagetitle = check_html($newpagetitle, nohtml);
    }
    if($pa=="showpage") {
       $sql = "SELECT title, cid FROM ".$prefix."_pages WHERE pid='$pid'";
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $page = $row[title];
      $cid = $row[cid];
      $sql = "SELECT title FROM ".$prefix."_pages_categories WHERE cid='$cid'";
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $cat = $row[title];
        $newpagetitle = "$cat $item_delim $page";
$newpagetitle = check_html($newpagetitle, nohtml);
   }
}

// Reviews
if($name=="Reviews"){
global $rop,$id;
$newpagetitle = "$name";
    if($rop=="showcontent") {
        $sql = "SELECT title FROM ".$prefix."_reviews WHERE id='$id'";
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $rev = $row[title];
        $newpagetitle = "$rev";
$newpagetitle = check_html($newpagetitle, nohtml);
    }
}

// Stories Archive
if($name=="Stories_Archive"){
global $sa,$year,$month_l;
$name=ereg_replace("_", " ", "$name");
$newpagetitle = "$name";
    if($sa=="show_month") {
        $newpagetitle = "$month_l, $year";
$newpagetitle = check_html($newpagetitle, nohtml);
    }
}

// Sections
if($name=="Sections"){
global $op,$secid,$artid;
$newpagetitle = "$name";
$newpagetitle = check_html($newpagetitle, nohtml);
    if($op=="listarticles") {
        $sql = "SELECT secname FROM ".$prefix."_sections WHERE secid='$secid'";
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $sec = $row[secname];
        $newpagetitle = "$sec";
$newpagetitle = check_html($newpagetitle, nohtml);
    }
    if($op=="viewarticle") {
       $sql = "SELECT title, secid FROM ".$prefix."_seccont WHERE artid='$artid'";
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $art = $row[title];
      $cid = $row[secid];
      $sql = "SELECT secname FROM ".$prefix."_sections WHERE secid='$cid'";
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $sec = $row[secname];
        $newpagetitle = "$sec $item_delim $art";
$newpagetitle = check_html($newpagetitle, nohtml);
   }
}

// Catchall for anything we don't have custom coding for
if($newpagetitle==""){
    $name=ereg_replace("_", " ", "$name");
    $newpagetitle="$sitename $item_delim $name";
$newpagetitle = check_html($newpagetitle, nohtml);
}

// Admin Pages
if(substr($_SERVER['REQUEST_URI'], 0, 10)=="/admin.php"){
    $newpagetitle="$item_delim Administration";
$newpagetitle = check_html($newpagetitle, nohtml);
}

// If we're on the main page let's use our site slogan
if($_SERVER['REQUEST_URI']=="/index.php" || $_SERVER['REQUEST_URI']=="/"){
    $newpagetitle="$slogan";
$newpagetitle = check_html($newpagetitle, nohtml);
}

// We're Done! Place the Title on the page
echo "<title>$newpagetitle</title>\n";

?>
บันทึกการเข้า

โอกาสไม่ได้มีไว้สำหรับทุกคน แต่โอกาสไว้เสมอสำหรับคนที่ไขว่คว้า If you touch me soft and gentle, If you look at me and smile. If you listen to me talk. Sometime before you talk, I will grow really grow.มีสติ เท่ากับมีสตางค์ Think big. Get big.
aum_mix
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 47
ออฟไลน์ ออฟไลน์

กระทู้: 1,153



ดูรายละเอียด เว็บไซต์
« ตอบ #1 เมื่อ: 17 ตุลาคม 2010, 17:12:16 »

Oop ซะด้วย  wanwan004
บันทึกการเข้า

ขายที่ดิน 31 ไร่ อยู่ ที่ดินสวย ทำเลดีติดถนน เหมาะแก่การลงทุนเป็นอย่างยิ่ง ที่ดินทำเลดี และที่ดิน 2,000 ไร่ จังหวัดกาญจนบุรี ที่ดินราคาดี
naytumz
Newbie
*

พลังน้ำใจ: 5
ออฟไลน์ ออฟไลน์

กระทู้: 49



ดูรายละเอียด
« ตอบ #2 เมื่อ: 17 ตุลาคม 2010, 17:36:13 »

echo "<title><?echo substr($newpagetitle,0,200);?></title>\n"; บรรทัดเดียว เพียวๆ เลยครับ  wanwan019
บันทึกการเข้า

 *Link Removed*
kitazawa1st
สมุนแก๊งเสียว
*

พลังน้ำใจ: 29
ออฟไลน์ ออฟไลน์

กระทู้: 563



ดูรายละเอียด
« ตอบ #3 เมื่อ: 17 ตุลาคม 2010, 17:43:34 »

ถ้าเป็นภาษาไทย แนะนำให้ใช้ mb_substr นะครับ
บันทึกการเข้า

เล็กสั้น ขยันซอย
ThaNaButS
Verified Seller
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 67
ออฟไลน์ ออฟไลน์

กระทู้: 1,197



ดูรายละเอียด
« ตอบ #4 เมื่อ: 17 ตุลาคม 2010, 18:18:01 »

ใช้ css ควบคุมความยาวตามกำหนด ถ้าเกินก็ซ่อนไว้

อิอิ ผมใช้แบบนี้ 5555
บันทึกการเข้า
kitazawa1st
สมุนแก๊งเสียว
*

พลังน้ำใจ: 29
ออฟไลน์ ออฟไลน์

กระทู้: 563



ดูรายละเอียด
« ตอบ #5 เมื่อ: 17 ตุลาคม 2010, 19:45:55 »

ใช้ css ควบคุมความยาวตามกำหนด ถ้าเกินก็ซ่อนไว้

อิอิ ผมใช้แบบนี้ 5555

title ครับท่าน  wanwan016
บันทึกการเข้า

เล็กสั้น ขยันซอย
nst_nk
Verified Seller
เจ้าพ่อบอร์ดเสียว
*

พลังน้ำใจ: 385
ออฟไลน์ ออฟไลน์

กระทู้: 3,396



ดูรายละเอียด เว็บไซต์
« ตอบ #6 เมื่อ: 17 ตุลาคม 2010, 19:55:28 »

iconv_substr(ตัวแปร, 0,จำนวนตัวอักษร, "UTF-8");

ผมใช้แบบนี้ครับ  wanwan020

ปล ผม encode เป็น UTF-8 นะเธอว์
บันทึกการเข้า


  ◤◤ รับเขียนระบบต่างๆครับ เช่น ระบบ Shipping , ร้านค้าออนไลน์ , อสังหาริมทรัพย์ , ระบบจัดการหลังบ้านทุกประเภท  สอบถามได้ครับ Line : bigznst ◥◥
เทพมังกร
Verified Seller
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 37
ออฟไลน์ ออฟไลน์

กระทู้: 1,314



ดูรายละเอียด
« ตอบ #7 เมื่อ: 17 ตุลาคม 2010, 20:38:18 »

อุ๊ยตายว๊ายๆๆๆกรี๊ดๆๆๆเทพเว็บนี้เยอะจริง ๆ หนูแก้ไขได้แย้วๆๆๆ thank ทุกท่านคร๊าบๆๆ
บันทึกการเข้า

โอกาสไม่ได้มีไว้สำหรับทุกคน แต่โอกาสไว้เสมอสำหรับคนที่ไขว่คว้า If you touch me soft and gentle, If you look at me and smile. If you listen to me talk. Sometime before you talk, I will grow really grow.มีสติ เท่ากับมีสตางค์ Think big. Get big.
หน้า: [1]   ขึ้นบน
พิมพ์