Skip to content

Instantly share code, notes, and snippets.

@bueltge

bueltge/gist:1362660

Created Nov 13, 2011
Embed
What would you like to do?
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