ak by to este niekto v buducnosti potreboval, tak som spravil jednu "malicku a velmi jednoduchu" funkciu
Pouziva sa podobne ako wordwrap(), len berie do uvahy bbcode tagy, ktore nerozdeluje...
Hadam tam nie je ziadna chyba:
Kód:
function wordwrap2($str,$maxLen,$break)
{
$arrBBCode = array("\[b\]","\[/b\]","\[i\]","\[/i\]","\[u\]","\[/u\]");
$arrStr = $arrIndexBBCode = array();
$rest = false;
while(strlen($str)>0) {
$start = $end = $tmpEnd = 0;
$start = strpos($str,'[',$end);
if($start!==false) {
$end = strpos($str,']',$start);
if($end!==false) {
$tmpEnd = $end;
if($start>0) {
$arrStr[] = substr($str,0,$start);
}
$item = substr($str,$start,$end-$start+1);
$isRegularBBCode = false;
foreach($arrBBCode as $bbcode) {
if(eregi("^".$bbcode."$",$item)) {
$isRegularBBCode = true;
$arrIndexBBCode[] = count($arrStr);
break;
}
}
if($isRegularBBCode || count($arrStr)==0) {
$arrStr[] = $item;
} else {
$arrStr[count($arrStr)-1] .= $item;
}
$str = substr($str,$end+1);
} else {
$rest = true;
}
} else {
$rest = true;
}
if($rest) {
$arrStr[] = substr($str,$tmpEnd);
break;
}
}
foreach($arrStr as $i => $item) {
if(!in_array($i,$arrIndexBBCode)) {
$arrItem = explode(' ',$item);
foreach($arrItem as $z => $word) {
if(strlen($word)>$maxLen) {
$arrItem[$z] = wordwrap($word,$maxLen,$break,true);
}
}
$arrStr[$i] = implode(' ',$arrItem);
}
}
return implode('',$arrStr);
}