note 14964 deleted from function.wordwrap by jimw

From: Date: Fri, 14 Dec 2001 20:39:51 +0000
Subject: note 14964 deleted from function.wordwrap by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-22776@lists.php.net to get a copy of this message
I added a line to that function word_wrap(), found at " http://morannon.the-infinite.org/archive/php/word_wrap ", because i need to convert \n 's to < br >'s to insert in my table... this function added one '\n' when encountering one other... it gives : /* word_wrap($string, $cols, $prefix) * * Takes $string, and wraps it on a per-word boundary (does not clip * words UNLESS the word is more than $cols long), no more than $cols per * line. Allows for optional prefix string for each line. (Was written to * easily format replies to e-mails, prefixing each line with "> ". * * Copyright 1999 Dominic J. Eidson, use as you wish, but give credit * where credit due. */ function word_wrap ($string, $cols = 80, $prefix = "") { $t_lines = split( "\n", $string); $outlines = ""; while(list(, $thisline) = each($t_lines)) { $thisline=substr($thisline,0,strpos($thisline,"\n")-1); //added by nayco, //nayco@netcourrier.com, http://nayco.free.fr if(strlen($thisline) > $cols) { $newline = ""; $t_l_lines = split(" ", $thisline); while(list(, $thisword) = each($t_l_lines)) { while((strlen($thisword) + strlen($prefix)) > $cols) { $cur_pos = 0; $outlines .= $prefix; for($num=0; $num < $cols-1; $num++) { $outlines .= $thisword[$num]; $cur_pos++; } $outlines .= "\n"; $thisword = substr($thisword, $cur_pos, (strlen($thisword)-$cur_pos)); } if((strlen($newline) + strlen($thisword)) > $cols) { $outlines .= $prefix.$newline."\n"; $newline = $thisword." "; } else { $newline .= $thisword." "; } } $outlines .= $prefix.$newline."\n"; } else { $outlines .= $prefix.$thisline."\n"; } } return $outlines; }

« previous php.notes (#22776) next »