Wrapping text in web pages
We can use the following function to wrap the text in web pages. While calling function we can give input text,limit and divider [optional]. This function breaks the line after the limit is reached.
<?php
function text_wrap($log_text, $limit, $divider=” “) {
$words = explode($divider, $log_text);
$word_count = count($words);
$char_counter = 0;
$block = “”;
foreach ($words as $value) {
$chars = strlen($value);
$block .= $value;
$char_counter = $char_counter + $chars;
if ($char_counter >= $limit) {
$block .= ”
“;
$char_counter = 0;
} else {
$block .= ” “;
}
}
return rtrim($block);
}
$text=”This is test lonnnnnnnggggggg string”;
$limit=5;
echo $output_text=text_wrap($text,$limit);
?>
