Tools, FAQ, Tutorials:
Reformatting a Paragraph of Text in PHP
How To Reformat a Paragraph of Text?
✍: FYIcenter.com
You can wordwrap() reformat a paragraph of text by wrapping lines with a fixed length. Here is a PHP script on how to use 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"); ?>
This script will print:
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.
The result is not really good because of the extra space characters. You need to learn preg_replace() to replace them with a single space character.
⇒ Converting Strings to Upper/Lower Case in PHP
⇐ Replacing a Substring in PHP
2024-02-27, 1849🔥, 5💬
Popular Posts:
How to Build my "sleep" Docker image from the Alpine image? I want the container to sleep for 10 hou...
How to use .NET CLR Types in Azure API Policy? By default, Azure imports many basic .NET CLR (Common...
Can Two Forms Be Nested? Can two forms be nested? The answer is no and yes: No. You can not nest two...
How to use "xsl-transform" Azure API Policy Statement? The "xsl-transform" Policy Statement allows y...
How to read Atom validation errors at w3.org? If your Atom feed has errors, the Atom validator at w3...