PHP wordwrap() Function
In this chapter you will learn:
- Definition for PHP wordwrap() Function
- Syntax for PHP wordwrap() Function
- Parameter for PHP wordwrap() Function
- Return for PHP wordwrap() Function
- Example - wrap long string
Definition
wordwrap()
function wrap lines against a length.
with no other parameters wordwrap()
wraps string at the
75-character mark using "\n" for new lines.
Syntax
PHP wordwrap() Function has the following syntax.
string wordwrap ( string str [, int line_length [, string break_char [, bool cut]]] )
Parameter
We can pass both the size and new line marker as the second and third parameters.
Return
Returns the given string wrapped at the specified length.
Example
<?PHP/*from j a v a 2 s. co m*/
$text = "This a long test from java2s.com. This a long test from java2s.com. This a long test from java2s.com. ";
$text = wordwrap($text, 20, "<br />");
print $text;
?>
Supply 1 as the fourth parameter enables "cut" mode: words over the limit will be cut up.
Here is an example of cut mode in action:
<?PHP// ja v a 2 s.c o m
$text = "This a long test from java2s.com. This a long test from java2s.com. This a long test from java2s.com.";
$text = wordwrap($text, 6, "\n", 1);
print $text;
?>
Next chapter...
What you will learn in the next chapter:
Home » PHP Tutorial » PHP String Functions