首页  >  文章  >  后端开发  >  php使用wordwrap格式化文本段落的方法_PHP

php使用wordwrap格式化文本段落的方法_PHP

WBOY
WBOY原创
2016-06-01 11:06:161119浏览

本文实例讲述了php使用wordwrap格式化文本段落的方法。分享给大家供大家参考。具体分析如下:

wordwrap()函数可以按照指定的固定行长度格式化文本段落,让段落看起来更加整齐

<&#63;php
$string = "TRADING ON MARGIN POSES ADDITIONAL
RISKS AND IS NOT SUITABLE FOR ALL
    INVESTORS.
A COMPLETE LIST OF THE RISKS ASSOCIATED WITH MARGIN TRADING IS
AVAILABLE IN THE MARGIN RISK DISCLOSURE DOCUMENT.";
$string = str_replace("\n", " ", $string);
$string = str_replace("\r", " ", $string);
print(wordwrap($string, 40)."\n");
&#63;>

上面的代码返回如下结果

TRADING ON MARGIN POSES ADDITIONAL
RISKS AND IS NOT SUITABLE FOR ALL
INVESTORS. A COMPLETE LIST OF THE
RISKS ASSOCIATED WITH MARGIN TRADING IS
AVAILABLE IN THE MARGIN RISK DISCLOSURE
DOCUMENT.

希望本文所述对大家的php程序设计有所帮助。

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn