Jump to content

remove non alpha characters from string


poe

Recommended Posts

lets say i have these 3 values in an array:

 

Bath & Body

Handbags

Home Accents

 

i want to remove all non alpha characters like ' '(space) and the '&'(amp sign) and replace with a single '_' (underscore). regardless of how many characters i remove i want to replace with just 1 '_'

 

so my example would look like:

 

Bath_Body

Handbags

Home_Accents

Link to comment
https://forums.phpfreaks.com/topic/73906-remove-non-alpha-characters-from-string/
Share on other sites

pocobueno, I'm pretty bad at regular expressions, so there's a great chance I'm wrong, but I think that would just replace each non alpha numeric character with _.... Meaning Bath & Body would be Bath___Body.

 

Also, what's with the s?  Once again, I'm terrible at regular expressions x.x

pocobueno, I'm pretty bad at regular expressions, so there's a great chance I'm wrong, but I think that would just replace each non alpha numeric character with _.... Meaning Bath & Body would be Bath___Body.

 

Also, what's with the s?  Once again, I'm terrible at regular expressions x.x

 

I didn't do that regular expression myself, I found it on a site and tested it. I'm pretty sure the "s" is for white spaces though.

 

Ah, your right about it returning "Bath___Body". I didn't take into account this part of the post: "regardless of how many characters i remove i want to replace with just 1 '_'".

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.