关于 WordPress 英文半角符号变成中文全角的解决方案

08.03.2008 by drivel - 1 Comment
Posted in 0pen Source, 水++

  WordPress 总是喜欢自作主张的把英文的单引号和双引号 ‘/” 变成中文的全角 ’ “ 。如图:

特别是在贴代码的时候,更是错误连篇。后台编辑发现符号都是没问题,但是显示出来就是有问题,万能的 Google 帮助俺找到了解决方案:

编辑 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;
    
}

即可,还有另外的一种解决方法,就是使用插件来解决

Plugin Name: Quotmarks Replacer
Version: 1.2.0
Author: Sparanoid
Author URI: http://blog.sparanoid.com/
Plugin URI: http://blog.sparanoid.com/archive/wordpress/quotmarks-replacer/
Description: 解决 WordPress 的全角引号问题,将全角的单引、和双引号和省略号替换成半角的格式,使后台输入的引号、省略号格式与前台读者浏览的引号格式保持一致。

不过尚未尝试…

  1. 搜易 说:

    我好像来过你的博客了。不过既然来了。给你留点东西吧 (*^__^*) 嘻嘻……

    [回复]