How do I call only the first few letters, like say 20 of the first letters from a text field of a table. If the ItemID = $a1[ItemID], then how do I select just 20 Letters from the Field Entry $a1[ItemText]? Any help would be appreciated. Thanks in Advance. Steven
$str=$a1[ItemText]; $length=20; $trailing='...'; // take off chars for the trailing $length-=strlen($trailing); if (strlen($str) > $length) { // string exceeded length, truncate and add trailing dots $string=substr($str,0,$length).$trailing; } else { // string was already short enough, return the string $string = $str; } PHP:
Here's what I used on the Bulletin hack I modified: function truncateEntry($string, $limit, $break=".", $pad="...") { # return with no change if string is shorter than $limit if(strlen($string) <= $limit) return; # is $break present between $limit and the end of the string? $breakpoint = strpos($string, $break, $limit); if($breakpoint < strlen($string) - 1) { # truncate string and pad $string = substr($string, 0, $breakpoint) . $pad; } return $string; } PHP: