PHP | wordwrap() Function
The wordwrap() function is a built-in function in PHP. This function wraps a given string to a given number of characters using a string break character.
Syntax:
string wordwrap ($str, $width, $break, $cut )
Parameters : The function accepts 4 parameters as shown in the above syntax and are described below:
- $str: This parameter specifies the input string which is needed to break up into lines.
- $width: This parameter specifies the number of characters at which the string will be wrapped. That is number of characters after whih the string will break.
- $break: This is an optional parameter and if specified appends the value at the point of breaking the string.
- $cut: It is a boolean parameter, if this parameter is set to TRUE, then the string is always wrapped at or before the specified width. That is it will also break a word from between if it comes in middle of the constraint specified by the parameter $width. When this parameter is set to FALSE the function does not split the word even if the width is smaller than the word width.
Return Value: The function returns a string wrapped upto specified length i.e. the string broken into lines on success, or FALSE on failure.
Below programs illustrate the wordwrap() function in PHP :
Program 1 :
<?php // Input string $str = "keep practicing at geeksforgeeks"; // prints the wrapped string echo wordwrap($str, 15, "\n", TRUE); ?> |
Output:
keep practicing at geeksforgeeks
Program 2 :
<?php // Input String $text = "Be a part of geeksforgeeks."; // Wrapped string $newtext = wordwrap($text, 8, "\n", TRUE); echo "$newtext\n"; ?> |
Output:
Be a part of geeksfor geeks.
Reference:
http://php.net/manual/en/function.wordwrap.php
Recommended Posts:
- HTML | DOM Style wordWrap Property
- How to call a function that return another function in JavaScript ?
- How to get the function name from within that function using JavaScript ?
- D3.js | d3.hcl() Function
- p5.js | tan() function
- D3.js | d3.lab() Function
- D3.js | d3.map.set() Function
- PHP | Ds\Map first() Function
- PHP Ds\Map sum() Function
- PHP | max( ) Function
- PHP | min( ) Function
- D3.js | d3.rgb() Function
- CSS | rgb() Function
- PHP | pos() Function
- PHP | key() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



