Regular Expressions 101

Community Patterns

Match all invalid PHP variable characters

1

Regular Expression
PCRE (PHP <7.3)

/
[^a-zA-Z_\x7f-\xff\d]
/
g

Description

This can be used in a preg_replace function to take any string value and strip all invalid characters to make a valid PHP variable

Submitted by Deathnerd - 8 years ago