توابع wordwrap() در PHP
مثال
خمیر کردن متن به طول مشخص:
<?php $str = "مثال یک کلمه طولانی: Supercalifragulistic"; echo wordwrap($str,15,"<br>\n"); ?>
تعریف و استفاده
توابع wordwrap() برای خمیر کردن متن به طول مشخص استفاده میشود.
Note:This function may leave whitespace characters at the beginning of the line.
Syntax
wordwrap(string,width,break,cut)
Parameter | Description |
---|---|
string | Required. Specify the string to be wrapped. |
width | Optional. Specify the maximum line width. The default is 75. |
break | Optional. Specify the character (or string) used as a separator. The default is "\n". |
cut |
Optional. Specify whether to wrap words longer than the specified width.
|
Technical Details
Return Value: | If successful, it returns the wrapped string. If failed, it returns FALSE. |
PHP Version: | 4.0.2+ |
Update Log: | In PHP 4.0.3, a new cut Parameters. |
More examples
Example 1
Using all parameters:
<?php $str = "An example of a long word is: Supercalifragulistic"; echo wordwrap($str,15,"<br>\n",TRUE); ?>
Example 2
String wrapping:
<?php $str = "An example of a long word is: Supercalifragulistic"; echo wordwrap($str,15); ?>
HTML output of the above code (please check the source code):
<!DOCTYPE html> <html> <body> An example of a long word is: Supercalifragulistic </body> </html>
Browser output of the above code:
An example of a long word: Supercalifragulistic