Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

shorten string (delete extra spaces)

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have an html form that inputs data into mysql db. The problem is somewhere along the query I am getting a bunch of space before and after the entered data. Does anybody now if there is php function shortens the string to only the entered data without extra spaces? Thanks in advance for any help...
 
$string=" there should be lotsa space in this ";

ltrim($string); // removes the space on the left
rtrim($string); // remove space on the right
trim($string); // removes it all


If you want to remove excess space from the middle of the string too:

$nospaces=eregi_replace(" +"," ", $string); // changes multiple spaces to just 1 space

***************************************
Party on, dudes!
[cannon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top