Any questions involving matching text strings to patterns - the pattern is called a "regular expression."
Moderator: General Moderators
-
shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
-
Contact:
Post
by shiznatix »
would this:
Code: Select all
$input = preg_replace('/\W+ \;/', '', $input);
replace everything that is NOT alphanumeric, a space, a underscore, or a semi-colon? I don't want this to do anything crazy that I am not aware of.
-
Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Post
by Chris Corbyn »
Nope... that would replace anything NOT alphanumeric, FOLLOWED BY a space, FOLLOWED BY a semi-colon
Use a character class to give groups of characters to replace

[abc]
-
feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Post
by feyd »
For your information, \W doesn't really do what you want either.
Code: Select all
[feyd@home]>php -r "$a = ''; for($i = 0; $i < 256; $i++, $a .= chr($i)); echo preg_replace('#\W#','',$a);"
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyzâèîÄÜ£₧ƒ¬▓│╡╣║└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷°∙·√ⁿ²■
-
shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
-
Contact:
Post
by shiznatix »
this does not work. it does not allow the ; character to pass through
-
shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
-
Contact:
Post
by shiznatix »
kinda a bump since i was not able to figure it out but instead of the ; character I need to let the - character through. this does not work
-
feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Post
by feyd »
-
shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
-
Contact:
Post
by shiznatix »
thanks mate. beautiful as always