Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Curly Quote Maker (See related posts)

// Run text through this function to make curly quotes


        function curl_me($curlme) {
        // This should take care of the single quotes
        $curlme = preg_replace("/'([dmst])([ .,?!\)\/<])/i","&#8217;$1$2",$curlme);
        $curlme = preg_replace("/'([lrv])([el])([ .,?!\)\/<])/i","&#8217;$1$2$3",$curlme);
        $curlme = preg_replace("/(?<!=)(\s+)'((?:[^ >])?(?:.*?)(?:[^=]))'(\s*[^>&])/Ss","$1&#8216;$2&#8217;$3",$curlme);

        // time for the doubles
        $curlme = preg_replace('/(?<!=)(\s+)"(?=[ >]])((?:.*?)(?:[^=])?)"(\s*[^>&])/Ss',"$1&#8220;$2&#8221;$3",$curlme);
        // multi-paragraph
        $curlme = preg_replace('/<p>"(.*)<\/p>/U',"<p>&#8220;$1</p>",$curlme);

        // not a quote, but whatever
        $curlme = str_replace('Ñ','&#8212;',$curlme);
        $curlme = str_replace('Ð','&#8211;',$curlme);
        return $curlme;
        }


You need to create an account or log in to post comments to this site.


Related Posts