Home > Article > Backend Development > How to use wordwrap to format text paragraphs in php, _PHP tutorial
The example in this article describes how PHP uses wordwrap to format text paragraphs. Share it with everyone for your reference. The specific analysis is as follows:
The wordwrap() function can format text paragraphs according to the specified fixed line length, making the paragraphs look neater
<?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"); ?>
The above code returns the following results
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.
I hope this article will be helpful to everyone’s PHP programming design.