2009-01 02

解决 WordPress 半角符号自动变成全角符号的方法

WordPress 总是喜欢自作主张的把英文的单引号和双引号变成中文的全角

尽管一般情况下,这种自作主张无伤大雅,但如果在张贴程序代码的时候,就足以导致致命错误。解决的方法:编辑在 WordPress 目录下的 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;
}


1 Comment

  1. Hi, interest post. I’ll write you later about few questions!

    KattyBlackyard

    2009.06.15
    23:52

您的 E-mail 将不会被公开

*

*

输入您的评论内容