Removing space

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
snicolas
Forum Commoner
Posts: 97
Joined: Tue Nov 09, 2004 8:32 am

Removing space

Post by snicolas »

Hi,

I am using this to remove unwanted tags from my posted data, but would like to keep the "space" if they entered one.

How can i modify this?
$s = ereg_replace("[^A-Za-z0-9]", "", $s);

thanks

s
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

Code: Select all

// this will allow a space
$s = ereg_replace("[^A-Za-z0-9 ]", "", $s);
// or this will allow whitespace characters (probably tab, space, new line, carriage return)
$s = ereg_replace("[^A-Za-z0-9\s]", "", $s);
you might wanna take a look at at php's strip_tags()
Post Reply