note 68139 added to function.substr

From: Date: Fri, 14 Jul 2006 17:55:50 +0000
Subject: note 68139 added to function.substr
Groups: php.notes 
Request: Send a blank email to php-notes+get-114787@lists.php.net to get a copy of this message
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. ---- Server IP: 81.94.227.69 Probable Submitter: 84.237.147.211 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.substr.php Edit -- http://master.php.net/note/edit/68139 Del: integrated -- http://master.php.net/note/delete/68139/integrated Del: useless -- http://master.php.net/note/delete/68139/useless Del: bad code -- http://master.php.net/note/delete/68139/bad+code Del: spam -- http://master.php.net/note/delete/68139/spam Del: non-english -- http://master.php.net/note/delete/68139/non-english Del: in docs -- http://master.php.net/note/delete/68139/in+docs Del: other reasons-- http://master.php.net/note/delete/68139 Reject -- http://master.php.net/note/reject/68139 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#114787) next »