note 68139 deleted from function.substr by bobby

From: Date: Thu, 14 Sep 2006 18:32:26 +0000
Subject: note 68139 deleted from function.substr by bobby
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-117192@lists.php.net to get a copy of this message
Note Submitter: elvijs ---- drifterlrsc, I like your idea, but this simple code makes my home server crash (Win32, Apache 2.0.58, PHP 5.1.4). It happens when the string is shorter than $n. So I changed the code to work right. Here is how it looks now: <?php function shorten($s,$n) { if (strlen($s)<$n) { exit; } $scan=0; while($scan==0){ if(substr($s,$n,1)==' '){ $scan=1; }else{ $n++; } } echo substr($s,0,$n) . "..."; } ?> Code below prevents function execution if the string is shorter than $n. if (strlen($s)<$n) { exit; } Excuse me for my bad English.

« previous php.notes (#117192) next »