php使用wordwrap重新格式化文本段落的简单示例

前端之家收集整理的这篇文章主要介绍了php使用wordwrap重新格式化文本段落的简单示例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
PHP使用wordwrap重新格式化文本段落感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编两巴掌来看看吧!
wordwrap()函数可以按照指定的固定行长度格式化文本段落,让段落看起来更加整齐

/**
 * PHP使用wordwrap重新格式化文本段落
 *
 * @param 
 * @arrange 512-笔记网: jb51.cc
 **/
$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");

/***   来自编程之家 jb51.cc(jb51.cc)   ***/
上面的代码返回如下结果
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.
原文链接:https://www.f2er.com/php/528370.html

猜你在找的PHP相关文章