PHP wordwrap() 函数
PHP 教程
· 2019-01-30 15:58:26
实例
按照指定长度对字符串进行折行处理:
<?php
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15,"<br>n");
?>
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15,"<br>n");
?>
定义和用法
wordwrap() 函数按照指定长度对字符串进行折行处理。
注释:该函数可能会在行的开头留下空格。
语法
wordwrap(string,width,break,cut)
| 参数 | 描述 |
|---|---|
| string | 必需。规定要进行折行的字符串。 |
| width | 可选。规定最大行宽度。默认是 75。 |
| break | 可选。规定作为分隔符使用的字符(字串断开字符)。默认是 "\n"。 |
| cut |
可选。规定是否对大于指定宽度的单词进行折行:
|
技术细节
| 返回值: | 如果成功,则返回折行后的字符串。如果失败,则返回 FALSE。 |
|---|---|
| PHP 版本: | 4.0.2+ |
| 更新日志: | 在 PHP 4.0.3 中,新增了 cut 参数。 |
更多实例
实例 1
使用所有的参数:
<?php
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15,"<br>n",TRUE);
?>
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15,"<br>n",TRUE);
?>
实例 2
对字符串进行折行:
<?php
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15);
?>
$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>
<html>
<body>
An example of a
long word is:
Supercalifragulistic
</body>
</html>
上面代码的浏览器输出如下:
An example of a long word is: Supercalifragulistic
点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html
Probability and Computing
Michael Mitzenmacher、Eli Upfal / Cambridge University Press / 2005-01-31 / USD 66.00
Assuming only an elementary background in discrete mathematics, this textbook is an excellent introduction to the probabilistic techniques and paradigms used in the development of probabilistic algori......一起来看看 《Probability and Computing》 这本书的介绍吧!