Word wrap function
We can use wordwrap funtion to wraps text into lines of a specific length.
Example
<?php
/**
* // May be the text in web page
* $input = “This is a sentence which contains some words.”;
*
* // Or text fetched from a database result
* $input = $row[’db_text’];
*
* // Then put it into the function
* $text = word_wrap($input);
*
* // Output the result
* echo $text;
*/
function word_wrap($text) {
// Define the characters to display per row
$chars = “20″;
$text = wordwrap($text, $chars, “<br />”, 1);
return $text;
}
?>
In above example, we are passing the input text parameter to word_wrap function. In that function, we are using wordwrap to wrap text into specific length in each row.
