note 97720 added to function.wordwrap

From: Date: Wed, 05 May 2010 08:43:45 +0000
Subject: note 97720 added to function.wordwrap
Groups: php.notes 
Request: Send a blank email to php-notes+get-168949@lists.php.net to get a copy of this message
I've written a simular wordwrap function that wraps on a given parameter rather the always a ' ' (space) <?php /** * This is a glorified wordwar function, its principle is the same * but it allows to split a string on a character chosen by you rather then * default space * @param string $string : the string that you want to split * @param string $delimiter : the delimiter is the character(s) that it should split on * @param string $splitChar : is the character that should be added as split character * @param int $amount : the amount of characters is should allow before thinking about splitting * @param int $offset : the offset from where is should start splitting * @return string */ public function stringWrap($string,$delimiter,$splitChar,$amount=75,$offset=0){ $retString = ''; #the string that will be returned $occ = 1; #counter to track occurences of wrap as multiplier for amount $prevCut = 0; # track where last the string was cut as starting point for next cut while($offset < strlen($string) && $offset = strpos($string,$delimiter,$offset+1)){ if($offset >= ($amount * $occ)){ $retString .= substr($string,$prevCut,$offset+1-$prevCut) . $splitChar; $prevCut = $offset+1; $occ++; } } return $retString; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 195.212.29.91 ---- Manual Page -- http://www.php.net/manual/en/function.wordwrap.php Edit -- https://master.php.net/note/edit/97720 Del: integrated -- https://master.php.net/note/delete/97720/integrated Del: useless -- https://master.php.net/note/delete/97720/useless Del: bad code -- https://master.php.net/note/delete/97720/bad+code Del: spam -- https://master.php.net/note/delete/97720/spam Del: non-english -- https://master.php.net/note/delete/97720/non-english Del: in docs -- https://master.php.net/note/delete/97720/in+docs Del: other reasons-- https://master.php.net/note/delete/97720 Reject -- https://master.php.net/note/reject/97720 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#168949) next »