Function subwords, gets words by max string length

/**
 * Get whole words from string...
 *
 * @param string $str String of words
 * @param integer $int Maximum string length
 */
function subwords($str, $int) {
	if (strlen($str) > $int) {
		$arr = str_word_count($str, 2);
		$blubb = false;
		foreach ($arr as $intPos => $strWord) {
			if ($blubb) return substr($str, 0, $intPos);
				if ($intPos > $int) $blubb = true;
		}
	}
}
  • Digg
  • del.icio.us
  • Facebook
  • Technorati
  • Twitthis
  • FriendFeed

POST A COMMENT

  • You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>