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, ∼2674🔥, 5💬
Popular Posts:
What is EPUB 3.0 Metadata "dc:description" Element? EPUB 3.0 Metadata "dc:description" is an optiona...
How to extend json.JSONEncoder class? I want to encode other Python data types to JSON. If you encod...
Where to get a JSON.stringify() Example Code in JavaScript? Here is a good JSON.stringify() example ...
How to access URL template parameters from "context.Request.Matched Parameters"object in Azure API P...
Why I am getting "The Windows SDK version 8.1 was not found" error, when building my C++ application...