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, ∼3165🔥, 0💬
Popular Posts:
How to validate the id_token signature received from Azure AD v2.0 authentication response? You can ...
How to add a new operation to an API on the Publisher Dashboard of an Azure API Management Service? ...
FYIcenter JSON Validator and Formatter is an online tool that checks for syntax errors of JSON text ...
How to Install Docker Desktop on Windows 10? You can follow this tutorial to Install Docker Desktop ...
How to create a navigation file like navigation.xhtml for an EPUB 3.0 book? At least one navigation ...