Page 1 of 1
Take the spaces out of a form
Posted: Tue Jul 25, 2006 5:18 pm
by jbcom41
Hi everyone
Can someone give a hand to a Scots man who is totally new to php?
All I want to do is take out all the spaces in a form that is returned. I know how to remove the white spaces from the beginning and end but how do you remove the ones in the middle of the text and numbers that are returned?
Any help would be greatly appreciated
Posted: Tue Jul 25, 2006 5:19 pm
by John Cartwright
trim() to remove excess whitespace around edges of strings, and
str_replace() for within the string.
Hi Scart
Posted: Tue Jul 25, 2006 5:37 pm
by jbcom41
Hi there
I have a form that returns a phone number but some people put a gap in between the regional code and home number.
So I am trying to take that gap out so the info before it is inserted into the database like this 0129447097 in stead of like this 01294 470907!
Any help would be great!
Posted: Tue Jul 25, 2006 5:43 pm
by feyd
Jcart gave you a solution. Since this is in Regex, what have you tried as far as patterns?
Posted: Tue Jul 25, 2006 5:43 pm
by jamiel
As jcart said...
Code: Select all
str_replace(' ', '', $phoneNumber)
Posted: Wed Jul 26, 2006 6:56 am
by bokehman
jamiel wrote:As jcart said...
Code: Select all
str_replace(' ', '', $phoneNumber)
I dont really like that. You are only looking for spaces. It would probably better to remove anything that is not a number... and since this is in the regex section...
Code: Select all
$phoneNumber = preg_replace('/[^\d]/', '', $phoneNumber);
bokehman
Posted: Wed Jul 26, 2006 5:21 pm
by jbcom41
Hi bokehman
thanks for that, very mcuh appreciated, would buy you a whisky if you were in Scotland!
Jbcom41