当字符串达到特定长度时将其换行:
<?php
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15,"<br>\n");
?>
亲自试一试 »
wordwrap() 函数在字符串达到特定长度时将其换行。
笔记:此函数可能会在行首留下空格。
wordwrap(
string,width,break,cut)
Parameter | Description |
---|---|
string | Required. Specifies the string to break up into lines |
width | Optional. Specifies the maximum line width. Default is 75 |
break | Optional. Specifies the characters to use as break. Default is "\n" |
cut | Optional. Specifies whether words longer than the specified width should be wrapped:
|
返回值: | 成功时返回分行的字符串,失败时返回 FALSE。 |
---|---|
PHP 版本: | 4.0.2+ |
变更日志: | 这个切PHP 4.0.3 中添加了参数 |
使用所有参数:
<?php
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15,"<br>\n",TRUE);
?>
亲自试一试 »
将字符串换行:
<?php
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15);
?>
上述代码的 HTML 输出将是(查看源代码):
<!DOCTYPE html>
<html>
<body>
An example of a
long word is:
Supercalifragulistic
</body>
</html>
上述代码的浏览器输出将是:
An example of a long word is: Supercalifragulistic
亲自试一试 »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!