当前位置:首页 > 网络编程 > 新手教程 > > 最少更改,实现 discuz 论坛的地址栏采用标题拼音

最少更改,实现 discuz 论坛的地址栏采用标题拼音

点击次数:23 次 发布日期:2008-11-16 10:00:45 作者:源代码网
源代码网推荐

源代码网整理以下问题描述:

源代码网整理以下最近有SEO的兄弟求我帮忙将 discuz 论坛的帖子标题搞到 url 里面去,比如

源代码网整理以下帖子为 "为什么花这样红"  ,对应的地址就是 weishenmohuazheyanghong-t-1-1.html

源代码网整理以下据说这样有助于搜索引擎搜录

源代码网整理以下问题解决:

源代码网整理以下我查看了discuz  的php代码,发现只需要做很小的改动就可以实现此功能:

源代码网整理以下现代码如下:

源代码网整理以下include/global.func.php 修改

源代码网整理以下function rewrite_thread($tid, $page = 0, $prevpage = 0, $extra = "") {

 $pinyin = pinyin(getthread($tid));
 return "<a href="".$pinyin."-t-".$tid."-".($page ? $page : 1)."-".($prevpage && !IS_ROBOT ? $prevpage : 1).".html"".stripslashes($extra).">";

}

源代码网整理以下function rewrite_forum($fid, $page = 0, $extra = "") {

 $pinyin = pinyin(getforum($fid));
 return "<a href="".$pinyin."-f-".$fid."-".($page ? $page : 1).".html"".stripslashes($extra).">";

}

源代码网整理以下在文件最下添加

源代码网整理以下include_once "phpsir_rewrite_pinyin.php";

源代码网整理以下新增 phpsir_rewrite_pinyin.php 文件内容

源代码网整理以下<?php
//phpsir
function pinyin($str,$ishead=0,$isclose=1)
{
 global $pinyins;
 global $charset;

源代码网整理以下 $str = strip_tags($str);

源代码网整理以下 

源代码网整理以下 if($charset == "utf-8")
 {
  $str = iconv("utf-8","gbk",$str);
 }

源代码网整理以下 //echo $str."<br/>";
 $restr = "";
 $str = trim($str);
 $slen = strlen($str);
 if($slen<2) return $str;
 if(count($pinyins)==0){
  $fp = fopen(dirname(__FILE__)."/pinyin.db","r");
  while(!feof($fp)){
   $line = trim(fgets($fp));
   $pinyins[$line[0].$line[1]] = substr($line,3,strlen($line)-3);
  }
  fclose($fp);
 }
 for($i=0;$i<$slen;$i++){
  if(ord($str[$i])>0x80)
  {
   $c = $str[$i].$str[$i+1];
   $i++;
   if(isset($pinyins[$c])){
    if($ishead==0) $restr .= $pinyins[$c];
    else $restr .= $pinyins[$c][0];
   }else $restr .= "-";
  }else if( eregi("[a-z0-9]",$str[$i]) ){ $restr .= $str[$i]; }
  else{ $restr .= "-";  }
 }
 if($isclose==0) unset($pinyins);
 //echo $restr."<br/>";

源代码网整理以下 $a = array("/-{2,}/","/^-{1,}/");
 $b = array("-","");
 $restr =  preg_replace($a,$b,$restr);

源代码网整理以下 return $restr;
}

源代码网整理以下function getthread($tid)
{
 global $db;
 global $tablepre;
 $a  = $db->query("select * from  {$tablepre}threads where tid = $tid ");
 $a =  $db->fetch_array($a);
 return $a["subject"];

源代码网整理以下}

源代码网整理以下function getforum($fid)
{
 global $db;
 global $tablepre;
 $a  = $db->query("select * from  {$tablepre}forums where fid = $fid ");
 $a =  $db->fetch_array($a);
 return $a["name"];

源代码网整理以下}

源代码网整理以下// end phpsir
?>

源代码网整理以下还有一点就是修改 .htaccess 加入

源代码网整理以下 

源代码网整理以下RewriteRule ^(.*)-f-([0-9]+)-([0-9]+).html$ forumdisplay.php?fid=$2&page=$3
RewriteRule ^(.*)-t-([0-9]+)-([0-9]+)-([0-9]+).html$ viewthread.php?tid=$2&extra=page\%3D$4&page=$3

源代码网整理以下 

源代码网整理以下搞定

源代码网整理以下 

源代码网整理以下llypp QQ  733905 于家中

源代码网整理以下

源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华