PHP/ Tips and Tricks/ Web development Truncate a string in PHP to the word closest to a certain number of characters sugatshr 0 Comments April 3, 2013 Using a regular expression $string = preg_replace(‘/s+?(S+)?$/’, ”, substr($string, 0, 100)); Post Views: 430