Word Limit of a string In PHP

http://jumnuoy.blogspot.com/2013/09/word-limit-of-string-in-php.html
Sometimes, if we need limit in the text, but if you are using the inbuilt functions of php then it breaks the words, and count only characters not the word. In this post you will see the very useful PHP function which can be used in limit of word. It counts word not counts the characters.

/*LIMIT TEXT*/

<?php
function countwordscustom($string, $limit) {
$str_code = explode(" ",$string); 
return implode("",array_splice($str_code,0,$limit)); 
}
?>
/*END LIMIT TEXT*/
If you want to use this function anywhere in your PHP file follow given example

<?php
$text = "Sabbay.co is a very good website the design of the website is very cool and good looking."; 
echo countwordscustom($text,10); 
?>

Sometimes, if we need limit in the text, but if you are using the inbuilt functions of php then it breaks the words, and count only characters not the word. In this post you will see the very useful PHP function which can be used in limit of word. It counts word not counts the characters.

/*LIMIT TEXT*/

<?php
function countwordscustom($string, $limit) {
$str_code = explode(" ",$string); 
return implode("",array_splice($str_code,0,$limit)); 
}
?>
/*END LIMIT TEXT*/
If you want to use this function anywhere in your PHP file follow given example

<?php
$text = "Sabbay.co is a very good website the design of the website is very cool and good looking."; 
echo countwordscustom($text,10); 
?>

0 comments:

Post a Comment

Followers

រឿង ដែលខានមើលមិនបាន

Contact us

Name

Email *

Message *

Your Language

Online

Copyright 2009 Simplex Celebs All rights reserved Designed by www.sruol9.com