0

I'm trying to replace invalid characters in a string by a '_' I tried using preg_replace like this

preg_replace('/[^a-zA-Z]+/', '_', $value);

but if my string was 'value1234' it's converted to 'value_' What I need is every single invalid character to be replaced by a '' which would return 'value___' I need to apply this with a complex regex so I want to avoid looping and testing each character if possible. Any idea on how to do this?

user1026605
  • 1,633
  • 4
  • 22
  • 58

0 Answers0