note 13421 deleted from ref.strings by tomsommer

From: Date: Wed, 15 Sep 2004 20:49:22 +0000
Subject: note 13421 deleted from ref.strings by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-76799@lists.php.net to get a copy of this message
Note Submitter: thanatos at wol dot be ---- I have written an *evil* little function that will cut a string on a character given. Features: 1) Minimum length. 2) If a string doesn't contain the character, it cuts your string to minimum length. 3) If the next character beyond the minimumlength equals the given character, it will cut the string to minimulength as well. Code: <?php function cuttext($tring,$cuton) { /* Define the character to cut on */ /* One could make an array with all characters to cut on */ /* But I wouldn't know how to :) */ $space=" "; if (!strstr($tring,$space)) { /* No space is found in the whole string: cut at 20th character */ $tring=substr($tring,0,$cuton); } if (substr($tring,$cuton,1)==$space) { /* 21st character is a space: cut at 20th character */ $tring=substr($tring,0,$cuton); } else { /* 21st Character is NOT a space: return to last space and cut there */ while ($teller <= $cuton) { if (substr($tring,$cuton-$teller,1)==$space) { $tring=substr($tring,0,$cuton-$teller); break; } $teller++; } } return $tring; } echo(cuttext("waf groink muha zz gruu wrrreea iii gargghhh >:)>:)",20)); ?>

« previous php.notes (#76799) next »