cleaned = preg_replace("/[^{$allow}a-zA-Z0-9]/", '', $string);

Read more of this post