Centos下安装php的mbstring扩展

php的mbstring扩展如果没有安装会导致一些问题,例如登陆phpMyAdmin的时候会提示没字符串编码和字符串处理库php_mbstring,有些程序中会用到mb_substr函数没有php的mbstring扩展当这些程序运行的时候通常会提示“Fatal error: Call to undefined function mb_substr()”,对于第二个问题可以用另一篇文章“mb_substr修正函数”解决。
但是如果你有自己的服务器或者vps的权限还是安装php的mbstring扩展好,下面是安装步骤,很简单:
SSH连接之后

yum -y install php-mbstring

然后编辑你的php.ini文件添加

extension=mbstring.so

最后重启httpd服务

service httpd restart

完成。

SEO WordPress

对于页面的description和keywords的设置WordPress 默认的情况是把在撰写日志的时候添加摘要(excerpt)作为description而把添加的标签(tag)作为keywords,但是大部分的人通常只添加keywords而很少会在发表日志的时候添加摘要(excerpt)这样一来很多页面就不会有description,下面的代码的作用就是如果写日志的时候给日志添加了摘要的就把摘要做为页面的Description,如果没有设置摘要的话,则自动截取文章的前120个字作为Description,而标签直接作为Keywords。
代码如下:

post_excerpt) {
         $description     = $post->post_excerpt;
     } else {
         $description = substr(strip_tags($post->post_content),0,120);
     }       $keywords = "";
            $tags = wp_get_post_tags($post->ID);
     foreach ($tags as $tag ) {
         $keywords = $keywords . $tag->name . ", ";
     } } ?>

上面代码请放到header.php中下面两行代码的上面


 

修改好文件之后查看源代码可能会发现一个问题就是如果内容是中文的有时候会发现description乱码
后来查了相关资料后发现是上面代码中的

$description = substr(strip_tags($post->post_content),0,120);

这行代码中的substr函数导致的把这行代码改成这样就可以了

$description = mb_substr(strip_tags($post->post_content),0,120,'utf-8');

改完之后如果发现打开页面出现错误,请看blog中的这篇文章
http://www.78wd.com/mb-substr/

yum install报错的解决办法

最近在Centos5.3下使用yum install安装软件的时候遇到“thread.error can’t start new thread”的报错提示

下面是解决办法

编辑 /etc/yum/pluginconf.d/fastestmirror.conf
将enabled=1修改为enabled=0,禁用该功能就可以了。

mb_substr修正函数

不支持mb_substr函数的环境中使用了mb_substr函数会出现“Fatal error: Call to undefined function mb_substr()”的提示,下面的函数是定义的替代mb_substr的函数,作用是一样的,用于不支持mb_substr的地方。

// Patch in multibyte support
if (!function_exists('mb_substr')) {
    function mb_substr($str, $start, $len = '', $encoding="UTF-8"){
        $limit = strlen($str);

        for ($s = 0; $start > 0;--$start) {// found the real start
            if ($s >= $limit)
                break;

            if ($str[$s] <= "\x7F")
                ++$s;
            else {
                ++$s; // skip length

                while ($str[$s] >= "\x80" && $str[$s] <= "\xBF")
                    ++$s;
            }
        }

        if ($len == '')
            return substr($str, $s);
        else
            for ($e = $s; $len > 0; --$len) {//found the real end
                if ($e >= $limit)
                    break;

                if ($str[$e] <= "\x7F")
                    ++$e;
                else {
                    ++$e;//skip length

                    while ($str[$e] >= "\x80" && $str[$e] <= "\xBF" && $e < $limit)
                        ++$e;
                }
            }

        return substr($str, $s, $e - $s);
    }
}

eAccelerator-0.9.6安装笔记

cd tmp
wget http://bart.eaccelerator.net/source/0.9.6/eaccelerator-0.9.6.tar.bz2
tar -jxvf eaccelerator-0.9.6.tar.bz2
cd eaccelerator-0.9.6
/usr/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/bin/php-config
make
make install

(注:以上文中“phpize”以及“php-config”的路径如果不知道可以使用find命令事先查找一下。)
安装完毕编辑php.ini将其安装为 PHP extension 模式
在php.ini中添加如下:

extension="eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.log_file = "/var/log/httpd/eaccelerator_log"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

最后创建/tmp/eaccelerator目录

mkdir /tmp/eaccelerator
chmod 0777 /tmp/eaccelerator
Page 1 of 4012345»102030...Last »