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
2016-10-13, 1236👍, 0💬
Popular Posts:
What properties and functions are supported on requests.models.Response objects? "requests" module s...
Why am I getting this "Docker failed to initialize" error? After installing the latest version of Do...
How to add request query string Parameters to my Azure API operation 2017 version to make it more us...
How To Submit Values without Using a Form in PHP? If you know the values you want to submit, you can...
How to access Request body from "context.Request.Body" object in Azure API Policy? Request body is t...