Skip to content

Instantly share code, notes, and snippets.

@patrickgilmour
Created October 13, 2015 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patrickgilmour/db6c8ae09560d67c0852 to your computer and use it in GitHub Desktop.
Save patrickgilmour/db6c8ae09560d67c0852 to your computer and use it in GitHub Desktop.
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));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment