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, ∼3356🔥, 0💬
Popular Posts:
Where to find EPUB Sample Files? Here is a list of EPUB sample files collected by FYIcenter.com team...
How to start Docker Daemon, "dockerd", on CentOS systems? If you have installed Docker on your CentO...
How To Merge Cells in a Column? If you want to merge multiple cells vertically in a row, you need to...
How to extend json.JSONEncoder class? I want to encode other Python data types to JSON. If you encod...
How to create a new API on the Publisher Dashboard of an Azure API Management Service? If you are ne...