Tag Archives: PCRE

Perl Compatible Regular Expressions – Classes & Shortcuts

If you are playing around with PCRE in php and are you having problems with using character classes or shortcuts, remember to check your php.ini file.

I was having problems and after much head starching, i found out that you have to disable magic quotes in the php.ini file. So run phpinfo() to locate the file and then ensure the below is set to “Off”.You could use stripslashes() within preg_match() to stop extra “\” being generated. But that is really extra code that you do not need.

; Magic quotes
;

; Magic quotes for incoming GET/POST/Cookie data.
magic_quotes_gpc = Off

; Magic quotes for runtime-generated data, e.g. data from SQL, from exec(), etc.
magic_quotes_runtime = Off

; Use Sybase-style magic quotes (escape ‘ with ” instead of \’).
magic_quotes_sybase = Off