note 53852 deleted from function.substr by bobby

From: Date: Thu, 14 Sep 2006 17:28:14 +0000
Subject: note 53852 deleted from function.substr by bobby
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-117180@lists.php.net to get a copy of this message
Note Submitter: jay ---- Better written version of my function below. <?php function elliStr($s,$n) { for ( $x = 0; $x < strlen($s); $x++ ) { $o = ($n+$x >= strlen($s) ? $s : ($s{$n+$x} == " " ? substr($s,0,$n+$x) . "..." : "")); if ( $o != "" ) { return $o; } } } print(elliStr("have a nice day", 7)); // returns: Have a nice... print(elliStr("have a nice day", 6)); // returns: Have a... ?>

« previous php.notes (#117180) next »