[thelist] Is this a list?
Ian Anderson
ian at zstudio.co.uk
Mon Sep 26 18:40:36 CDT 2005
Matt Warden wrote:
> I don't see how it would have any effect on search engines or non-JS
> users, except that they would not get the final opportunity to cancel
> the operation.
Durr, you are quite right; I was being a goose. I suddenly lurched into
an alternative universe where we were talking about links with
JavaScript confirmation, rather than form submission.
My bad...I'm having a mid-life crisis, I think.
<tip type="php - string display" author="Ian Anderson">
Truncating data upon display is a common task, and there are lots of
ways to do it. Thing is, I hate seeing words being broken when this
happens because it's typographically poor form. This humble PHP function
takes a string and a maximum display length; if the supplied string is
greater than the length, it is truncated to the last space before the
maxlength and ellipsis is added. If the string is less than the
threshold, it is displayed in total.
function elide($str, $len) {
$strlen = strlen($str);
if ($strlen > $len) {
$str = substr($str, 0, $len);
$lastSpacePos = strrpos($str, " ");
$str = substr($str, 0, $lastSpacePos) . '...';
return $str;
} else {
return $str;
}
}
</tip>
--
_________________________________________________
zStudio - Web development and accessibility
http://zStudio.co.uk
Snippetz.net BETA - Online code library
File, manage and re-use your code snippets online
http://snippetz.net
More information about the thelist
mailing list