today we had a task to edit all the comments from our users where they put comments such as:

you are soooooooooooooooooooooooooooooooooool coooollllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll

as you can see, it just messes up because the word cool is so long that it goes beyond our webpage and it makes it look bad..

for quite some time now, i wanted to come up with a function where i can get rid of this.

but how do you do it..

well, with php you can.

so we partnered with www.webune.com to come up with a fucntion that cleans up this mess..

so this we came up with this function:

PHP CODE:
function remove($string,$word_limit) {
	$words = explode(" ", $string );
	for( $i = 0; $i < count($words); ++$i ){
		if(strlen($words[$i]) > $word_limit) {
			$words[$i] = substr($words[$i], 0, $word_limit );
		} 
	}
	$words = implode(" ", $words );
	return $words ;
}


now all you have to do is echo the function and provide the values in the function

Exampe:

PHP CODE

$word_limit = 10;
$string = 'sssssssssssssooooooooooooooooooooooooooo coooolllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll';

echo remove($string, $word_limit);