We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42046
    • 436 Posts
    Does anyone have particular feelings/experience with this topic and the technicalities that go with it?

    I have some people that aren't even aware of the difference, some that don't care and some that insist on smart quotes from a typographical perspective.

    When it's insisted upon it can create numerous problems. Most rich text editors require the use of "insert special character" when not pasting text, when pasting text it can work but but even Redactor doesn't convert them into proper html code which I'd prefer. Entering into text boxes like pagetitle requires the teaching of keyboard shortcuts.

    Is there a more streamlined solution that could be implemented with maybe MODX events to parse and convert specific characters? [ed. note: absent42 last edited this post 13 years ago.]
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You could use a plugin and replace normal quotes with smart quotes. This would probably be best done when the requested resource is being parsed, probably somewhere towards the end of parsing, like the OnWebPageComplete event. This function seems to work as-is, and can most likely be adapted to your needs.
      function smart_quotes($text) {
        $pattern = '/"((.)*?)"/i';
        $text = preg_replace($pattern,"“\\1”",stripslashes($text));
        $text = str_replace("\"","-",$text);
        $text = addslashes($text);
        return $text;
      }

      http://www.php.net/manual/en/function.preg-replace.php#76665
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 3749
        • 24,544 Posts
        For HTML output, you might want something like this:

        function smart_quotes($text) {
          $pattern = '/"((.)*?)"/i';
          $text = preg_replace($pattern,'$ldquo;' . "\\1" . '”',stripslashes($text));
          $text = str_replace("\"","-",$text);
          $text = addslashes($text);
          return $text;
        }


        The problem is that you might have a description of someone who is 5'10" tall or something similar somewhere in your output. It won't matter unless it's inside a set of double quotes, but if it happens, all the quotes from there on will be backwards. wink
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 42046
          • 436 Posts
          Thanks for both your replies Susan and Bob. I'm going to play around with the code you both suggested for my specific situation.

          Like you implied Bob, there's a problem with recognition of the correct usage. MS Word somehow manages to figure out when a quote should curl, in what direction and when not, and in my experience does a pretty good job at guessing. I've searched but a generic catch all php equivalent but seems elusive.
            • 3749
            • 24,544 Posts
            It's really pretty rare for a lone double quote to end up inside two other double quotes. I'd just hope it doesn't happen and replace the solo one with &quot (followed by a semicolon) if it does. The regex will ignore that.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting