Today i will show you how you can remove all or some white spaces from your string in PHP

Lets say for example, i have this:

CODE:
$string = " THIS IS A LONG WORD ";


as you can see from the example, i have spaces at the beginning and at the end of the string.

TO REMOVE THE WHITE SPACE AT THE BEGINNING AND AT THE END USE THIS:
CODE:
$string = trim($string);


To remove white spaces from the beginning (left) use this:
CODE:
$string = ltrim($string);

To remove white spaces from the end(right) use this:
CODE:
$string = rtrim($string);



Hey, So how about if i wanted to remove all the white spaces from " THIS IS A LONG WORD ", ok, we can do that with this code:

CODE:
<?
$string = " THIS IS A LONG WORD ";
$string = str_replace(" ","",$string );
echo $string;
?>

Output:
CODE:
THISISALONGWORD


Thanks to the folks at www.webune.com for their support on this.
NOTE: if you want these scripts to work, you need to have PHP, if you dont have php, you can sign up with www.webune.com and sign up with one of their PHP web hosting plans.

Hopes this helps.