JIMMY THE CODE JIMMY THE CODE - 10 months ago 22
PHP Question

How can I set POST data to null if not alphanumeric?

I am posting allot of form data to my query. I want to set POST data to null or remove the special characters if not alphanumeric and the rest keep there values?

Is there a quick way I can do this in bulk?

if (!isset($_POST) || !ctype_alnum($_POST)){

// POST equals null

// Nothing

foreach($_POST as $key => $value)
    if (empty($value) || !ctype_alnum($value))
        // remove non alphanumeric chars
        $_POST[$key] = preg_replace("/[^[:alnum:]]/i","",$value);