Word wrap function

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.

Leave a Reply


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.