patrickgilmour
10/13/2015 - 9:38 PM

Truncates a string to the nearest defined word boundary.

Truncates a string to the nearest defined word boundary.

<?php

// Truncates a string to 275 characters to the nearest word
// from: preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, 201));

$the_substring = preg_replace('/\s+?(\S+)?$/', '', substr( $the_string , 0, 275));