Php Word wrap

Word wrap
Description

A function that takes a string of text and wraps it into lines of a length that you determine. Can be useful for guestbooks, news posting scripts etc. to prevent the layout breaking.
The code





/**

* Example usage:

*

* // Your text

* $text = "This is a sentence which contains some words.";

*

* // Or from a database result

* $text = $row['text'];

*

* // Then put it into the function

* $text = word_wrap($text);

*

* // Output the result

* echo $text;

*/



function word_wrap($text) {



// Define the characters to display per row

$chars = "10";



$text = wordwrap($text, $chars, "
", 1);



return $text;



}



?>

Posted in |