实例按照指定长度对字符串进行折行处理: <?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。 |
---|
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 vsprintf() 函数 PHP utf8_decode() 函数 |