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
构建可扩展的Web站点
Cal Henderson / 徐宁 / 电子工业出版社 / 2008 / 58.00元
随着Web 2.0网站的蓬勃发展,如何成功地构建可扩展的Web站点成为网站开发人员必备的技能。本书是Flickr.com的主力开发人员讲解构建可扩展的Web站点的经典之作。本书主要介绍了Web应用程序的概念、体系结构、硬件需求、开发环境的原则及国际化、本地化和Unicode等基本内容,并为解决Web应用程序的数据安全、电子邮件整合、远程服务交互、应用程序优化、扩展、监测和预警、开放API等问题提供......一起来看看 《构建可扩展的Web站点》 这本书的介绍吧!