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, ∼4066🔥, 0💬
Popular Posts:
dev.FYIcenter.com is a Website for software developer looking for software development technologies,...
How to use urllib.parse.urlencode() function to encode HTTP POST data? My form data has special char...
How To Pass Arrays By References? in PHP? Like normal variables, you can pass an array by reference ...
How To Read a File in Binary Mode in PHP? If you have a file that stores binary data, like an execut...
How To Avoid the Undefined Index Error in PHP? If you don't want your PHP page to give out errors as...