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;
?>
$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.
Quote:
how to remove white spaces php trim how to remove white spaces php trim PHP strip remove white space from end of string - PHP Content Need to remove the white space at the end of a string before recording the data. Use PHP's rtrim(). Remove whitespace from a text string using the PHP trim function Remove wallpaperama whitespace from a text string using the PHP trim function ... then you'll know that user input can often have white space before or after the text Trimming White Space Any programs to trim white space/ remove all white space in HTML file? Hi, Are there any scripts or tools to trim/remove all white spaces in a html/php/ scripts file? sql trim white spaces problem SELECT TRIM([DISTINCT] Table1.[Name]) AS Name, PHP Tutorials: Trimming White Space PHP strip remove white space from end of string FAQTs - Knowledge Base - View Entry - How might you remove wallpaperama white php perl string javascript removing vb space removing space perl space php space whitespace from string space in add programs leading space php whitesed space string space space remover wallpaperama perl whitespace add javascript space c++ whitejava space java space add programs python space coldfusion space deleting space trailing how to whitehtml space c# space whitefrom string vb net space extra space sql space java whitespace in html asp space space from text vbscript space perl leading space delete space space at beginning space from a string perl removing space removing space in reports java wallpaperama string space whitejavascript space c css space css removing space vb removing picture space c++ space python whiteasp net space asp net space in html space from add python sed delete space sed linux space perl trailing space deleting whitenet in java how to space extra whitedeleting removing space from a string trailing whitespace in string stringwallpaperama whitefrom a string space removal delete whitehow to net space trailing space all space in add all space removing whitehtml css perl characters xml regex xsl non php xslt functions split function replace strip wallpaperama trailing string leading all leading trim multiple trailing search blank file from delete