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, ∼3080🔥, 5💬
Popular Posts:
How To Change Text Fonts for Some Parts of a Paragraph? If you want to change text fonts or colors f...
How to Install Docker Desktop on Windows 10? You can follow this tutorial to Install Docker Desktop ...
How to build a test service operation to dump everything from the "context.Request" object in the re...
How To Read a File in Binary Mode in PHP? If you have a file that stores binary data, like an execut...
How to use the Atom Online Validator at w3.org? w3.org feed validation service is provided at http:/...