😅How to Truncate a string in PHP to the word closest to a certain number of characters? (ok)

https://stackoverflow.com/questions/3161816/truncate-a-string-to-first-n-characters-of-a-string-and-add-three-dots-if-any-ch

Example 1

$string = preg_replace('/\s+/', ' ', str_replace(array('-', '_'), " ",get_the_title()));
echo preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, 6));

Last updated