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, ∼3601🔥, 0💬
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 Read the Entire File into a Single String in PHP? If you have a file, and you want to read th...
How to use 'choose ... when ..." policy statements to control execution flows? If you want to contro...
Where to get a JSON.stringify() Example Code in JavaScript? Here is a good JSON.stringify() example ...
What are "*..." and "**..." Wildcard Parameters in Function Definitions? If you want to define a fun...