note 97121 added to function.wordwrap
| From: | maxime dot faye at gmail dot com | Date: | Fri, 02 Apr 2010 13:14:23 +0000 |
| Subject: | note 97121 added to function.wordwrap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-167643@lists.php.net to get a copy of this message | ||
Updating "andrnag at yandex dot ru" utf8_wordwrap function with the cutting parameter like
the original wordwrap() function :
<?php
function MBWordwrap($p_sToWrap, $p_iWidth = 75, $p_sBreak = "\n", $p_bCut = false) {
$sOut = '';
$sEncoding = mb_detect_encoding($p_sToWrap);
$sEncoding = mb_strtolower($sEncoding);
if(mb_strpos($sEncoding, 'utf', 0, $sEncoding) !== false) {
$p_sToWrap = preg_split('/([\x20\r\n\t]++|\xc2\xa0)/sSX', $p_sToWrap, -1,
PREG_SPLIT_NO_EMPTY);
if($p_bCut){
for($i = 0; $i <= (count($p_sToWrap) - 1); $i++){
$iLength = mb_strlen($p_sToWrap[$i], $sEncoding);
if($iLength >= $p_iWidth){
$sOldValue = $p_sToWrap[$i];
$sTemp = mb_substr($p_sToWrap[$i], 0, $p_iWidth, $sEncoding);
$sTempRestLength = mb_strlen($sOldValue, $sEncoding) - $p_iWidth;
$sTempRest = mb_substr($sOldValue, ($p_iWidth - 1), $sTempRestLength, $sEncoding);
$p_sToWrap[$i] = $sTemp;
$sOldValueNext = $p_sToWrap[$i + 1];
$p_sToWrap[$i + 1] = $sTempRest;
for($j = (count($p_sToWrap) - 1); $j < ($i + 1); $j--){
if($j == ($i + 2)){
$p_sToWrap[$j + 1] = $sOldValueNext;
}
else{
$p_sToWrap[$j + 1] = $p_sToWrap[$j];
}
}
}
}
}
$iLength = 0;
foreach ($p_sToWrap as $sValue) {
$sValue .= ' ';
$iTemp = mb_strlen($sValue, $sEncoding);
$iLength += $iTemp;
if ($iLength >= $p_iWidth) {
$sOut .= $p_sBreak . $sValue;
$iLength = $iTemp;
}
else {
$sOut .= $sValue;
}
}
}
else {
$sOut = wordwrap($p_sToWrap, $p_iWidth, $p_sBreak, $p_bCut);
}
return $sOut;
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 80.89.121.10
----
Manual Page -- http://www.php.net/manual/en/function.wordwrap.php
Edit -- https://master.php.net/note/edit/97121
Del: integrated -- https://master.php.net/note/delete/97121/integrated
Del: useless -- https://master.php.net/note/delete/97121/useless
Del: bad code -- https://master.php.net/note/delete/97121/bad+code
Del: spam -- https://master.php.net/note/delete/97121/spam
Del: non-english -- https://master.php.net/note/delete/97121/non-english
Del: in docs -- https://master.php.net/note/delete/97121/in+docs
Del: other reasons-- https://master.php.net/note/delete/97121
Reject -- https://master.php.net/note/reject/97121
Search -- https://master.php.net/manage/user-notes.php