How to remove white space from a string in PHP?
How to remove white space from a string in PHP?
Here the PHP trim() function is used to remove the white space.
The PHP trim() function is used to remove whitespace including non-breaking spaces, newlines, and tabs from the beginning and end of the string.
The whitespace which occurs in the middle of the string cannot be removed.
For example:
<?php $my_str = ' Welcome to Tutorial Republic '; echo strlen($my_str); // Outputs: 33 $trimmed_str = trim($my_str); echo strlen($trimmed_str); // Outputs: 28 ?>