note 97720 deleted from function.wordwrap by visualmind
| From: | visualmind@php.net | Date: | Wed, 05 May 2010 09:06:13 +0000 |
| Subject: | note 97720 deleted from function.wordwrap by visualmind | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-168951@lists.php.net to get a copy of this message | ||
Note Submitter: Esser Jan
----
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;
}
?>