How Can I Remove Whitespace from a String

Example

Below is an example of the trim() function in action,
which removes all whitespace from the left and right side of a string

Actual PHP Output

GeoTashfeen
GeoTashfeen
GeoTashfeen

The output of the above PHP code is:
These two are not recognized as the same

After we use the trim() function, then all the search queries will be the same, despite the white space.
To prove this, run the following PHP code:

The output of the above PHP code is:

Before the trim() function :
These 2 strings are not the same
These 2 strings are also not the same

After the trim() function :
These 2 strings are the same
These 2 strings are also the same

How to Remove All Spaces in a String

If we want to remove all spaces in a string with PHP,
the trim() function would not be used.
Instead, we could use the str_replace() function in the following way:

Actual PHP Output

WhatdayoftheweekisJuly4ththisyear?