Truncate text using php
March 19, 2010
2 comments
<?php
function truncate($string, $length='' , $k = ''){
if( $length == '') $length = 50;
if( $k == '') $k = '...';
settype($string, 'string');
settype($length, 'integer');
for($a = 0; $a < $length AND $a < strlen($string); $a++){
$output .= $string[$a];
}
if( strlen($string) > $length)
$output .= $k;
return($output);
}
?>
truncate text using php
$my_string = 'I am kajal Mondol.I live in Kolkata.'; echo truncate($my_string); echo truncate($my_string,10); echo truncate($my_string,10,',,,');
This will output:
I am kajal Mondol.I live in Kolkata. I am kajal... I am kajal,,,
This function truncates a variable to a character length, default is 50.
‘…’ is the default text to append if truncation occurs.
Second parameter determines how many characters to truncate to.
Categories: Php
if( strlen($string) > $length)
Drupal 6 Simple Views Slideshow Setup In Aquia Marina
March 17, 2010
Leave a comment
Categories: Drupal


