note 50857 deleted from function.wordwrap by danbrown

From: Date: Sun, 17 May 2009 18:36:02 +0000
Subject: note 50857 deleted from function.wordwrap by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155143@lists.php.net to get a copy of this message
Note Submitter: philippe [%a%] niquille [dot] com ---- 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.

« previous php.notes (#155143) next »