Jump to content

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 '_'".

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.