Skip to content

Instantly share code, notes, and snippets.

@bueltge
Created November 13, 2011 20:44
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 bueltge/1362660 to your computer and use it in GitHub Desktop.
Save bueltge/1362660 to your computer and use it in GitHub Desktop.
Extract word from a string given a position in php
function extractWord($text, $position){
$words = explode(' ', $text);
$characters = -1;
foreach($words as $word){
$characters += strlen($word);
if($characters >= $position){
return $word;
}
}
return '';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment