note 51144 added to function.substr

From: Date: Mon, 21 Mar 2005 19:19:25 +0000
Subject: note 51144 added to function.substr
Groups: php.notes 
Request: Send a blank email to php-notes+get-86756@lists.php.net to get a copy of this message
Well this is a script I wrote, what it does is chop up long words with malicious meaning into several parts. This way, a chat in a table will not get stretched anymore. <?php function text($string,$limit=20,$chop=10){ $text = explode(" ",$string); while(list($key, $value) = each($text)){ $length = strlen($value); if($length >=20){ for($i=0;$i<=$length;$i+=10){ $new .= substr($value, $i, 10); $new .= " "; } $post .= $new; } elseif($length <=15){ $post .= $value; } $post .= " "; } return($post); } // for example, this would return: $output = text("Well this text doesn't get cut up, yet thisssssssssssssssssssssssss one does.", 10, 5); echo($output); // "Well this text doesn't get cup up, yet thiss sssss sssss sssss sssss sss one does." ?> I hope it was useful.. :) ---- Manual Page -- http://www.php.net/manual/en/function.substr.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51144 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51144&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51144&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51144&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51144&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51144&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51144&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#86756) next »