note 84103 modified in function.substr by danbrown

From: Date: Fri, 28 Nov 2008 20:14:47 +0000
Subject: note 84103 modified in function.substr by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-147193@lists.php.net to get a copy of this message
joao dot martins at plako dot net 26-Mar-2008 09:14 ben at enemy dot dk 10-Feb-2008 05:48 Updated function. The previous one will return empty value if the $string has no letter spaces. This is usefull if some of your strings have only one word. <?php function cutText($string, $setlength) { $length = $setlength; if($length<strlen($string)){ while (($string{$length} != " ") AND ($length > 0)) { $length--; } if ($length == 0) return substr($string, 0, $setlength); else return substr($string, 0, $length); }else return $string; } ?> --was-- joao dot martins at plako dot net 26-Mar-2008 09:14 ben at enemy dot dk 10-Feb-2008 05:48 Updated function. The previous one will return empty value if the $string has no letter spaces. This is usefull if some of your strings have only one word. function cutText($string, $setlength) { $length = $setlength; if($length<strlen($string)){ while (($string{$length} != " ") AND ($length > 0)) { $length--; } if ($length == 0) return substr($string, 0, $setlength); else return substr($string, 0, $length); }else return $string; } http://php.net/manual/en/function.substr.php

« previous php.notes (#147193) next »