$search = substr($search_string, 0, -1);
It is only removing last one space only. Some times in last character after having 2 or more spaces how to remove all spaces after word last character and if some times end user entered first character space how to remove also first character?
You could use trim
:
$s = " blabla ";
$s = trim($s, " ");
use trim()
:
trim — Strip whitespace (or other characters) from the beginning and end of a string
$search_string = trim($search_string);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With