You can avoid the afterburner by preceding it with a backslash - $targetFile = preg_replace('/[^A-Za-z0-9-.\/]/', '', $targetFileDirty);
Alternatively, and perhaps better, you can use different delimiters, for example, $targetFile = preg_replace('#[^A-Za-z0-9-./]#', '', $targetFileDirty);
source share