让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.”
答案 0 :(得分:1)
试试这个:
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
}
答案 1 :(得分:0)
已经有一个名为“SmartyPants”的插件,最初是由Daring Fireball成名的John Gruber创建的。它最初是为MoveableType
创建的但是其他人已经创建了可以使用的PHP版本。看看这个:
http://michelf.com/projects/php-smartypants/
或者您可以在Google上搜索“SmartyPants PHP”,然后您会找到更多选项。
另外作为参考,人们也将这些称为“智能引号”。