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, ∼3996🔥, 0💬
Popular Posts:
How to run CMD Commands in Dockerfile to change Windows Docker images? When building a new Windows i...
How to Install Docker Desktop 2.5.0 on Windows 10? You can follow this tutorial to Install Docker De...
How to install .NET Framework in Visual Studio Community 2017? I have the Visual Studio Installer in...
Why I am getting "LNK1104: cannot open file 'MSCOREE.lib'" error when building a C++/CLI program? Vi...
What validation keywords I can use in JSON Schema to specifically validate JSON Array values? The cu...