本文實例講述了php使用wordwrap格式化文本段落的方法。分享給大家供大家參考。具體分析如下:
wordwrap()函數可以按照指定的固定行長度格式化文本段落,讓段落看起來更加整齊
<?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"); ?>
上面的代碼返回如下結果
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程序設計有所幫助。