|
หัวข้อ: เทพ php ซ่อยข่อยแน่ ปรับแต่ง title ไม่ให้เกิน 200 ตัวอักษร เริ่มหัวข้อโดย: เทพมังกร ที่ 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"; ?> หัวข้อ: Re: เทพ php ซ่อยข่อยแน่ ปรับแต่ง title ไม่ให้เกิน 200 ตัวอักษร เริ่มหัวข้อโดย: aum_mix ที่ 17 ตุลาคม 2010, 17:12:16 Oop ซะด้วย :wanwan004:
หัวข้อ: Re: เทพ php ซ่อยข่อยแน่ ปรับแต่ง title ไม่ให้เกิน 200 ตัวอักษร เริ่มหัวข้อโดย: naytumz ที่ 17 ตุลาคม 2010, 17:36:13 echo "<title><?echo substr($newpagetitle,0,200);?></title>\n"; บรรทัดเดียว เพียวๆ เลยครับ :wanwan019:
หัวข้อ: Re: เทพ php ซ่อยข่อยแน่ ปรับแต่ง title ไม่ให้เกิน 200 ตัวอักษร เริ่มหัวข้อโดย: kitazawa1st ที่ 17 ตุลาคม 2010, 17:43:34 ถ้าเป็นภาษาไทย แนะนำให้ใช้ mb_substr นะครับ
หัวข้อ: Re: เทพ php ซ่อยข่อยแน่ ปรับแต่ง title ไม่ให้เกิน 200 ตัวอักษร เริ่มหัวข้อโดย: ThaNaButS ที่ 17 ตุลาคม 2010, 18:18:01 ใช้ css ควบคุมความยาวตามกำหนด ถ้าเกินก็ซ่อนไว้
อิอิ ผมใช้แบบนี้ 5555 หัวข้อ: Re: เทพ php ซ่อยข่อยแน่ ปรับแต่ง title ไม่ให้เกิน 200 ตัวอักษร เริ่มหัวข้อโดย: kitazawa1st ที่ 17 ตุลาคม 2010, 19:45:55 ใช้ css ควบคุมความยาวตามกำหนด ถ้าเกินก็ซ่อนไว้ อิอิ ผมใช้แบบนี้ 5555 title ครับท่าน :wanwan016: หัวข้อ: Re: เทพ php ซ่อยข่อยแน่ ปรับแต่ง title ไม่ให้เกิน 200 ตัวอักษร เริ่มหัวข้อโดย: nst_nk ที่ 17 ตุลาคม 2010, 19:55:28 iconv_substr(ตัวแปร, 0,จำนวนตัวอักษร, "UTF-8");
ผมใช้แบบนี้ครับ :wanwan020: ปล ผม encode เป็น UTF-8 นะเธอว์ หัวข้อ: Re: เทพ php ซ่อยข่อยแน่ ปรับแต่ง title ไม่ให้เกิน 200 ตัวอักษร เริ่มหัวข้อโดย: เทพมังกร ที่ 17 ตุลาคม 2010, 20:38:18 อุ๊ยตายว๊ายๆๆๆกรี๊ดๆๆๆเทพเว็บนี้เยอะจริง ๆ หนูแก้ไขได้แย้วๆๆๆ thank ทุกท่านคร๊าบๆๆ
|