让PHP将常规引号转换为漂亮引号的最好方法是什么?
即,转换为-
直接引号:
Poe's Great Aunt Sally said Poe said, "Once upon a midday dreary."
转换为卷曲的“漂亮的引号”:
Poe’s Great Aunt Sally said Poe said, “Once upon a midday dreary.”
发布于 2010-08-03 05:47:27
试试这个:
function convert_quotes($string) {
$string = " " . $string . " "; //add spaces to beginning and end of string to catch strings that begin and/or end with quotes
$search = array(" '", //use spaces to determine which direction a quote show curl.
"' ",
"'",
' "',
'" '
);
$replace = array("‘",
"’",
"’",
"“",
"”"
);
return trim(str_replace($search, $replace, $string)); //replace quotes and trim spaces added at beginning of function
}发布于 2010-08-03 06:10:53
已经有一个名为"SmartyPants“的插件,最初是由John Gruber创建的,他因”大胆的火球“而出名。它最初是为MoveableType创建的
但其他人已经创建了可供您使用的PHP版本。看看这个:
http://michelf.com/projects/php-smartypants/
或者你可以在谷歌上搜索"SmartyPants PHP“,你会找到更多的选项。
同样为了参考,人们也将这些称为“智能引号”。
https://stackoverflow.com/questions/3392009
复制相似问题