note 77138 deleted from function.wordwrap by danbrown

From: Date: Sun, 17 May 2009 18:29:32 +0000
Subject: note 77138 deleted from function.wordwrap by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155127@lists.php.net to get a copy of this message
Note Submitter: luismorrison at gmail dot com ---- i wrote this by mistake because i didn't know that the same function already exists in PHP.. well shit happens, its quite simple but maybe this will help you someday in your project. The difference is that the one i wrote, called 'splitstroverflow()', cuts given string and parses into arrays to do whatever you like with them. <?php function splitstroverflow($cadena,$longitud) { $pri_renglon = array(); $seg_renglon = array(); $palabras = explode(" ",trim($cadena)); for ($i = 0; $i < count($palabras); $i++) { $sum += strlen($palabras[$i])+1; if ($sum >= $longitud) $seg_renglon[] = $palabras[$i] . " "; else $pri_renglon[] = $palabras[$i] . " "; } for ($i = 0; $i < count($pri_renglon); $i++) $renglones[0] .= $pri_renglon[$i]; for ($i = 0; $i < count($seg_renglon); $i++) $renglones[1] .= $seg_renglon[$i]; return $renglones; } ?> Usage: <?php splitstroverflow(str longString,int lenght); $myrow = splitstroverflow("This is my long long long string",18); // the array counts 2 elements // Array // ( // [0] => "This is my long" // [1] => "long long string" // ) ?>

« previous php.notes (#155127) next »