- Forums
- PHP
- PHP Tutorial Remove Spaces From String Removing Blank Space From Sentence
This Page Contains information about PHP Tutorial Remove Spaces From String Removing Blank Space From Sentence By wallpaperama in category PHP with 1 Replies. [1009], Last Updated: Sat May 18, 2024
wallpaperama
Tue Mar 06, 2007
1 Comments
924 Visits
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.
https://www.wallpaperama.com/forums/php-tutorial-remove-spaces-from-string-removing-blank-space-from-sentence-t919.html