Created
November 13, 2011 20:44
-
-
Save bueltge/1362660 to your computer and use it in GitHub Desktop.
Extract word from a string given a position in php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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