2010-08-02 28 views
1

什麼是讓PHP將普通引號轉換爲漂亮引號的最佳方式。PHP Pretty Quotes

即轉換 -

直引號:

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.」

+2

請參閱[ 將直引號轉換爲卷引號的想法 ](http://stackoverflow.com/questions/509685/ideas-for-converting-straight-quotes-to-curly-quotes)。 – 2010-08-02 21:43:59

回答

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 
} 
0

已經有一個名爲「SmartyPants」的插件,最初由Daring Fireball成名的John Gruber創建。它最初是爲MoveableType創建的

但是其他人已經創建了可以使用的PHP版本。看看這個:

http://michelf.com/projects/php-smartypants/

或者你可以運行一個谷歌搜索「聰明的傢伙PHP」,你會發現更多的選擇。

另外供參考,人們也稱這些爲「聰明的引號」。

+0

說到SmartyPants,我有一個關於如何獲得post/get字段轉換爲捲曲引號的問題。 http://stackoverflow.com/questions/3391924/smartypants-php-not-working-for-strings-submitted-by-post-get – ina 2010-08-02 22:19:36