Skip to content

Instantly share code, notes, and snippets.

@iowillhoit
Created August 8, 2013 17:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iowillhoit/6186825 to your computer and use it in GitHub Desktop.
Save iowillhoit/6186825 to your computer and use it in GitHub Desktop.
Changes uppercase sequences to lowercase and wraps in a span with the "text-transform:uppercase" style. This is helpful to lower your spam rating on email newsletters. Most spam filters don't like seeing ALL CAPS, because it's usually IS spam..
<?php
function replaceUpperCaseWithCss($matches){
$lower = strtolower($matches[0]);
return sprintf('<span style="text-transform:uppercase;">%s</span>', $lower);
}
function findUpperCaseSequences($text){
return preg_replace_callback("/[^a-z\ ]{2,}(\ [^a-z\ ]+)*\b/", "replaceUpperCaseWithCss", $text);
}
$string = "I CAN! DO mutliple WO-RDS, but I ignore WORDS with One Capital Letter";
echo findUpperCaseSequences($string);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment