這篇文章主要介紹了php使用wordwrap格式化文本段落的方法,涉及wordwrap函數的使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了php使用wordwrap格式化文本段落的方法。分享給大家供大家參考。具體分析如下:
wordwrap()函數可以按照指定的固定行長度格式化文本段落,讓段落看起來更加整齊
? 1 2 3 4 5 6 7 8 9 10 <?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"); ?>上面的代碼返回如下結果
? 1 2 3 4 5 6 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程序設計有所幫助。