Wrap a string according to the specified length:
<?php$str = "An example of a long word is: Supercalifragulistic";echo wordwrap($str,15,"<br>n");?>The wordwrap() function wraps a string according to the specified length.
Note: This function may leave spaces at the beginning of lines.
wordwrap( string,width,break,cut )
parameter | describe |
---|---|
string | Required. Specifies the string to be wrapped. |
width | Optional. Specifies the maximum line width. The default is 75. |
break | Optional. Specifies the character used as a delimiter (string breaking character). The default is "n". |
cut | Optional. Specifies whether words larger than the specified width should be wrapped: FALSE - Default. Do not break the line TRUE - wrap line |
Return value: | If successful, the wrapped string is returned. If it fails, returns FALSE. |
---|---|
PHP version: | 4.0.2+ |
Update log: | In PHP 4.0.3, the cut parameter is added. |
Use all parameters:
<?php$str = "An example of a long word is: Supercalifragulistic";echo wordwrap($str,15,"<br>n",TRUE);?>Wrap a string:
<?php$str = "An example of a long word is: Supercalifragulistic";echo wordwrap($str,15);?>The HTML output of the above code is as follows (view source code):
<!DOCTYPE html><html><body>An example of along word is:Supercalifragulistic</body></html>The browser output of the above code is as follows:
An example of a long word is: Supercalifragulistic