A1:笑得海潮 B3:冒泡的崔 D2:Cornell University,Computer Vision Group H2:冰河的博客 G3:丕子博客 K1:MLA CHINA K4:斯坦福视觉实验室 L4:MIT 机器学习实验室
现在的位置: 首页技术>正文
cat_ico23 category
wordpress英文符号半角自动全角问题
发表于796 天前 技术 评论数 10 ⁄ 被围观 536 次+

今天粘贴代码时候发现半角的" " 都变成了乱七八糟的有半角有全角“”,代码粘下来用的时候就困难比较多了,总结一下解决方法:
1、插件方法
Quotmarks Replacer是一个通过禁用wptexturize函数来解决WordPress自动将半角的单引号、双引号和省略号转换为全角标点的问题。使后台输入的标点格式与前台读者浏览的标点格式保持一致的插件。
插件地址:http://sparanoid.com/archive/wordpress/quotmarks-replacer/
2、直接更改WP安装目录下wp-includes/formatting.php更改里面的过滤参数就可以避免这种情况了。具体如下:
#文件:wp-includes/formatting.php,将以下代码

$static_characters = array_merge(array('---', ' -- ', '--', 'xn–', '...', '``', '\'s', '\'\'', ' (tm)'), $cockney);
$static_replacements = array_merge(array('—', ' — ', '–', 'xn--', '…', '“', '’s', '”', ' ™'), $cockneyreplace);
$dynamic_characters = array('/\'(\d\d(?:’|\')?s)/', '/(\s|\A|")\'/', '/(\d+)"/', '/(\d+)\'/', '/(\S)\'([^\'\s])/', '/(\s|\A)"(?!\s)/', '/"(\s|\S|\Z)/', '/\'([\s.]|\Z)/', '/(\d+)x(\d+)/');
$dynamic_replacements = array('’$1','$1‘', '$1″', '$1′', '$1’$2', '$1“$2', '”$1', '’$1', '$1×$2');

替换成

$static_characters = array_merge(array(), $cockney);
$static_replacements = array_merge(array(), $cockneyreplace);
$dynamic_characters = array('/(\d+)x(\d+)/');
$dynamic_replacements = array('$1×$2');

3、编辑 wp-includes/formatting.php
将如下代码

for ( $i = 0; $i < $stop; $i++ ) {
         $curl = $textarr[$i];

        if (isset($curl{0}) && '<' != $curl{0} && '[' != $curl{0} && $next && !$has_pre_parent) { // If it's not a tag
            // static strings
            $curl = str_replace($static_characters, $static_replacements, $curl);
            // regular expressions
            $curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl);
        } elseif (strpos($curl, '<code') !== false || strpos($curl, '<kbd') !== false || strpos($curl, '<style') !== false || strpos($curl, '<script') !== false) {
            $next = false;
        } elseif (strpos($curl, '<pre') !== false) {
            $has_pre_parent = true;
        } elseif (strpos($curl, '</pre>') !== false) {
            $has_pre_parent = false;
        } else {
            $next = true;
        }

        $curl = preg_replace('/&([^#])(?![a-zA-Z1-4]{1,8};)/', '&#038;$1', $curl);
        $output .= $curl;
    }

改为

for ( $i = 0; $i < $stop; $i++ ) {
         $curl = $textarr[$i];

        if (isset($curl{0}) && '<' != $curl{0} && '[' != $curl{0} && $next && !$has_pre_parent) { // If it's not a tag
            // static strings
            //$curl = str_replace($static_characters, $static_replacements, $curl);
            // regular expressions
            //$curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl);
        } elseif (strpos($curl, '<code') !== false || strpos($curl, '<kbd') !== false || strpos($curl, '<style') !== false || strpos($curl, '<script') !== false) {
            $next = false;
        } elseif (strpos($curl, '<pre') !== false) {
            $has_pre_parent = true;
        } elseif (strpos($curl, '</pre>') !== false) {
            $has_pre_parent = false;
        } else {
            $next = true;
        }

        $curl = preg_replace('/&([^#])(?![a-zA-Z1-4]{1,8};)/', '&#038;$1', $curl);
        $output .= $curl;
    }

方法2和3其实使之一样,修改过滤方法的具体内容而已,只是地方不一样,3是直接注销掉过滤方法的调用了。希望不会出什么别的问题。

参考:1、http://blog.everalan.com/194.html
2、http://anylinux.net/post/627.html

wordpress英文符号半角自动全角问题:目前有10 条留言

  1. 卢木公木公 : 2009年12月03日9:39 下午 回复

    坐个沙发慢慢看!

  2. 卢松松 : 2009年12月03日11:19 下午 回复

    做个板凳看一楼

  3. 丕子 : 2009年12月03日11:32 下午 回复

    @卢松松
    行了 我可以截图宣传这个了

  4. 北京热水器维修 : 2009年12月04日9:18 上午 回复

    很实用的耶

  5. 丕子 : 2009年12月04日11:52 上午 回复

    @北京热水器维修
    呵呵 那就用呗

  6. 好名字要隐藏 : 2009年12月04日12:25 下午 回复

    我没买票就来看了。还免费学习。蒽蒽。

  7. 丕子 : 2009年12月04日1:15 下午 回复

    @好名字要隐藏
    补票吧 哈哈

  8. 超人 : 2009年12月04日1:35 下午 回复

    我这好像没出现那问题.

  9. 腌生肉 : 2009年12月04日2:44 下午 回复

    我是来打酱油的。

  10. 丕子 : 2009年12月04日3:23 下午 回复

    @超人
    哦 你是英文版的wp的吧

给我留言


/ 快捷键:Ctrl+Enter

无觅相关文章插件,快速提升流量

不想听你唠叨×