Skip to content

Instantly share code, notes, and snippets.

@pgchamberlin
Last active December 14, 2015 05:59
Show Gist options
  • Save pgchamberlin/5039270 to your computer and use it in GitHub Desktop.
Save pgchamberlin/5039270 to your computer and use it in GitHub Desktop.
In response to @smashingmag's tweet: https://twitter.com/smashingmag/status/306416073408929792 an alternative method.
<?php
function nbspBetweenLastWords( $text, $minWords = 3 ) {
if (substr_count($text, ' ') >= $minWords - 1) {
return substr_replace($text, '&nbsp;', strrpos($text, ' '), 1);
}
return $text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment