Created
October 31, 2012 05:32
-
-
Save mukundthanki/3985015 to your computer and use it in GitHub Desktop.
Limit Words To String( title, content, anything )
This file contains 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
<?php | |
function string_limit_words($string, $word_limit){ | |
$words = explode(' ', $string, ($word_limit + 1)); | |
if(count($words) > $word_limit) | |
array_pop($words); | |
return implode(' ', $words); | |
} | |
//Usage | |
//Suppose for wordpress content/excerpt length | |
$excerpt = get_the_excerpt(); | |
echo string_limit_words($excerpt,12); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment