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");
?>

定义和用法

wordwrap() 函数按照指定长度对字符串进行折行处理。

注释:该函数可能会在行的开头留下空格。

语法


wordwrap(string,width,break,cut)


参数 描述
string 必需。规定要进行折行的字符串。
width 可选。规定最大行宽度。默认是 75。
break 可选。规定作为分隔符使用的字符(字串断开字符)。默认是 "\n"。
cut 可选。规定是否对大于指定宽度的单词进行折行:
  • FALSE - 默认。不折行
  • TRUE - 折行

技术细节

返回值: 如果成功,则返回折行后的字符串。如果失败,则返回 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);
?>

实例 2

对字符串进行折行:

<?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

点击查看所有 PHP 教程 文章: https://www.codercto.com/courses/l/5.html

查看所有标签

Web 2.0 Architectures

Web 2.0 Architectures

Duane Nickull、Dion Hinchcliffe、James Governor / O'Reilly / 2009 / USD 34.99

The "Web 2.0" phenomena has become more pervasive than ever before. It is impacting the very fabric of our society and presents opportunities for those with knowledge. The individuals who understand t......一起来看看 《Web 2.0 Architectures》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码