Skip to content

Instantly share code, notes, and snippets.

@benrothe
Created November 2, 2013 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save benrothe/7281205 to your computer and use it in GitHub Desktop.
Save benrothe/7281205 to your computer and use it in GitHub Desktop.
A TextExpander snippet to convert clipboard contents: "Straight" quotes to “curly”, double-hyphens to em-dashes and three periods to ellipses.
#!/usr/bin/env php
<?php
$str = `pbpaste`;
$str = preg_replace('/(^|[-\xe2\x80\x94\/(\[{"\s])\'/', "$1\xe2\x80\x98", $str);
$str = preg_replace('/\'/', "\xe2\x80\x99", $str);
$str = preg_replace('/(^|[-\xe2\x80\x94\/(\[{\xe2\x80\x98\s])"/', "$1\xe2\x80\x9c", $str);
$str = preg_replace('/"/', "\xe2\x80\x9d", $str);
$str = preg_replace('/--/', "\xe2\x80\x94", $str);
$str = preg_replace('/\.\.\./', "\xe2\x80\xa6", $str);
echo $str;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment