hello! i found a nice function that i would like to use but unfortunately there is a problem i can not solve.
for my notepool device it would be great to use php's wordwrap function but because the string that needs to be wordwrapped contains also html tags i can not use this function like this. on php.net (manual: wordwrap) i found a user contribution with a wordwrap function that skips html tags (and forces words to split at a desired width). the bad thing about it is that in the output some characters are missing. example: as i enter this url into my form: http://www2.snm-hgkz.ch/~rieger/notepool/addnote.php that's the output: h tp://www2.snm-hgkz ch/~rieger/notepool/ ddnote.php (obviously some caracters are missing, the first 't' of http or the 'a' of addnote.php for instance.) can you tell me what needs to be modified to get rid of this side effect (or do you have another idea how to use wordwrap in a way it skips html tags and forces words to split)? ---------------------------------------------------------------------------- this is the function: function sheep_wordwrap($str,$cols,$non_prop,$cut,$exclude1,$exclude2){ $count=0; $tagcount=0; $str_len=strlen($str); //$cut=" $cut "; $calcwidth=0; for ($i=1; $i<=$str_len;$i++){ $str_len=strlen($str); if ($str[$i]==$exclude1) $tagcount++; elseif ($str[$i]==$exclude2){ if ($tagcount>0) $tagcount--; } else{ if (($tagcount==0)){ if (($str[$i]==' ') || ($str[$i]=="\n")) $calcwidth=0; else{ if ($non_prop){ if (ereg("([QWOSDGCM#@m%w]+)",$str[$i],$matches)) $calcwidth=$calcwidth+7; elseif (ereg("([I?\|()\"]+)",$str[$i],$matches)) $calcwidth=$calcwidth+4; elseif (ereg("([i']+)",$str[$i],$matches)) $calcwidth=$calcwidth+2; elseif (ereg("([!]+)",$str[$i],$matches)) $calcwidth=$calcwidth+3; else{ $calcwidth=$calcwidth+5; } } else{ $calcwidth++; } if ($calcwidth>$cols){ $str=substr($str,0,$i-1).$cut.substr($str,$i,$str_len-1); $calcwidth=0; } } } } } return $str; //moby rules at 5am! :) } ---------------------------------------------------------------------------- and here i call it: $str = $message; $cols = 100; $cut = "\n"; $non_prop = "true"; $exclude1 = "<"; $exclude2 = ">"; $str = sheep_wordwrap($str,$cols,$non_prop,$cut,$exclude1,$exclude2); echo $str; thanks a lot for your help! philipp ---------------------------------------------------------------------------- * http://www2.snm-hgkz.ch/~rieger/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php