Tools, FAQ, Tutorials:
Ways to Remove Leading and Trailing White Spaces in PHP
How Many ways to Remove Leading and Trailing White Spaces?
✍: FYIcenter.com
There are 4 PHP functions you can use remove white space characters from the beginning and/or the end of a string:
White space characters are defined as:
Here is a PHP script example of trimming strings:
<?php
$text = "\t \t Hello world!\t \t ";
$leftTrimmed = ltrim($text);
$rightTrimmed = rtrim($text);
$bothTrimmed = trim($text);
print("leftTrimmed = ($leftTrimmed)\n");
print("rightTrimmed = ($rightTrimmed)\n");
print("bothTrimmed = ($bothTrimmed)\n");
?>
This script will print:
leftTrimmed = (Hello world! ) rightTrimmed = ( Hello world!) bothTrimmed = (Hello world!)
⇒ Remove Trailing New Line Character in PHP
⇐ Counting the Number of Characters in PHP
2016-10-13, ∼3425🔥, 0💬
Popular Posts:
Where to find tutorials on OpenID? Here is a large collection of tutorials to answer many frequently...
How to reinstall npm with a node version manager? I am getting permission errors with the current ve...
How To Open Standard Output as a File Handle in PHP? If you want to open the standard output as a fi...
How To Create an Array with a Sequence of Integers or Characters in PHP? The quickest way to create ...
How to Install Docker Desktop 2.5.0 on Windows 10? You can follow this tutorial to Install Docker De...