note 50857 added to function.wordwrap

From: Date: Fri, 11 Mar 2005 18:01:30 +0000
Subject: note 50857 added to function.wordwrap
Groups: php.notes 
Request: Send a blank email to php-notes+get-86258@lists.php.net to get a copy of this message
I changed the wordsplit function a bit, so that it returns an array containing all the text chunks, not only the cutted one: <? function _split_text($text) { $MAX_LENGTH = 160; $split=explode(" ",$text); $numwords = count($split); $i=0; //while counter $a = 1; //counts the text chunks $amount = ceil(strlen($text)/($MAX_LENGTH-5)); //get total word chunks while($i < $numwords){ $len = (strlen($newtext[$a])+strlen($split[$i])); //get length of the active chunk if($len>($MAX_LENGTH-5)){ //do we have to start a new one? $a++; $newtext[$a] = "[$a/$amount] "; //Adds [1/2] }else{ if($i == 0) $newtext[$a] = "[$a/$amount] "; $newtext[$a]=$newtext[$a]." ".$split[$i]; $i++; } } return $newtext; } } ?> I used the function for a sms sending script to automatically cut the user's message. ---- Manual Page -- http://www.php.net/manual/en/function.wordwrap.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+50857 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50857&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50857&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50857&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50857&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50857&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+50857&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#86258) next »