PHP Tutorial Remove Spaces From String Removing Blank Space From Sentence

Mobile
feeds
Welcome Login | Register

PHP Tutorial Remove Spaces From String Removing Blank Space From Sentence
  Forums Index
      » Forums
        » » PHP Tutorial Remove Spaces From String Removing Blank Space From Sentence



PHP Tutorial Remove Spaces From String Removing Blank Space From Sentence
Post Description:
Post Tags: php, tutorial, remove, spaces, from, string, removing, blank, space, from, sentence,
This Post Has Been Viewed 467 Times Since Tue Mar 06, 2007 2:13 pm Posted By hostman with 1 replies
PHP Tutorial Remove Spaces From String Removing Blank Space From Sentence
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.



Leave Your Comments






Share
URL:
You can use this HTML code to put it on your website to show your friends this wallpaper. Use this code on your profile like myspace, friendster, Facebook or others. Just Copy and Paste it in your HTML on your websites



Fourms BBCODE:
BBCODE is use on forums. You can put this code on all your BBCODE enabled forums like PhpBB, vBulletin® and others. Just Copy and Paste this code on your Posts and Replies on your forums





Comments and replies About PHP Tutorial Remove Spaces From String Removing Blank Space From Sentence




:: 1 :: Reply #74865 Reply By juli On Fri Oct 10, 2008 6:41 pm
not really what i was looking for is how to remove white spaces php using trim to how to remove white spaces from php with trim but i guess you have a PHP strip remove white and when i try it for myslef ths pacering didnt work at all but i 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 i dont know why you have to do this php this script is uselss i tell you why dont you waste my time on this id didnt learn anythog