The Note You're Voting On
ojs-hp at web dot de ¶ 16 years ago
After I got some problems with my function to convert a BB-text into HTML. Long words didn't really fit into the layout and only wordwarp() also added breaks to words which would fit into the layout or destroy the other HTML-tags....
So this is my solution. Only words with strlen() >= 40 are edited with wordwarp().
<?php
function bb2html($bb) {
$words= explode(' ', $bb); // string to array
foreach ($words as $word) {
$break = 0;
for ($i = 0; $i < strlen($word); $i++) {
if ($break >= 40) {
$word= wordwrap($word, 40, '-<br>', true); //add <br> every 40 chars
$break = 0;
}
$break++;
}
$newText[] = $word; //add word to array
}
$bb = implode(' ', $newText); //array to string
return $bb;
}
?>