...

View Full Version : preg_replace whitespace removal



durangod
12-06-2010, 04:19 PM
hi, im curious if i have the below code why is my string length 1 after POST if i enter 5 spaces. should it not be null


//get rid of whitespace



$var['username'] = preg_replace('/\s\s+/', ' ', $var['username']);

$stlen = strlen($var['username']);


update: or am i just replacing it with itself basically..

would it be better this way



$var['username'] = str_replace(' ', '', $var['username']);

if someone enters any spaces i want them removed i can capture string length.

durangod
12-06-2010, 04:49 PM
i got it i just tossed in a trim in front of the preg replace

durangod
12-06-2010, 05:04 PM
ok i guess i need help on this it works accept for
1s2s3s4s5ssssss

(s) meaning space..
it does not remove those internal spaces..

durangod
12-06-2010, 05:32 PM
ok i got it i used the string replace function and it passed all tests..



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum