Skip to content

Instantly share code, notes, and snippets.

@alixaxel
Created January 29, 2013 15:10
Show Gist options
  • Save alixaxel/4664963 to your computer and use it in GitHub Desktop.
Save alixaxel/4664963 to your computer and use it in GitHub Desktop.
<?php
public static function Typography($string, $quotes = true)
{
if ($quotes === true)
{
$string = preg_replace(array("~'([^']+)'~", '~"([^"]+)"~'), array('‘$1’', '“$1”'), $string);
}
return preg_replace(array('~[.]{2,}~', '~--~', '~-~', '~(?<=\d)(st|nd|rd|th)\b~i'), array('…', '—', '–', '<sup>$1</sup>'), $string);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment