Filtering input data I created a function that filters data and I want to know if it's fully secure to filter user input data.

function user_input_data($data,$options) {
    $output = null;
    $error_msg = "";
    $check_length = false;
    $options_fetch = array(
    @$length_max = $options["length_max"],
    @$length_min = $options["length_min"],
    $data_type = $options["data_type"],
    );

    if($length_min &amp;&amp; $length_max) {
        $check_length = true;
    }

    if($data_type == "only_letters") {

        if (preg_match('/^[\p{Arabic}a-zA-Z]+\h?[\p{Arabic}a-zA-Z]*$/u', $data)) {
             $output = $data;
        }else{
            $output = false;
        }
    }

    if($data_type == "only_letters_numbers") {

        if (preg_match('/^[\p{Arabic}a-zA-Z0-9]+\h?[\p{Arabic}a-zA-Z0-9]*$/u', $data)) {                    
            $output = $data;     
        }else{
            $output = false;
        }
    }          

    if($data_type == "string") {
        $output = htmlspecialchars($data,ENT_QUOTES,"UTF-8",true);
    }
    if($data_type == "text") {
        $output = strip_tags($data);
    }
    if($data_type == "integer") {
        if(filter_var($data,FILTER_VALIDATE_INT)) {
            $output = $data;
        }
    }
    if($data_type == "float") {
        if(filter_var($data,FILTER_VALIDATE_FLOAT)) {
            $output = $data;
        }
    }
    if($data_type == "boolean") {
        if(filter_var($data,FILTER_VALIDATE_BOOLEAN)) {
            $output = $data;
        }
    }
    if($data_type == "email") {
        if(filter_var($data,FILTER_VALIDATE_EMAIL)) {
            $output = $data;
        }
    }
    if($data_type == "url") {
        if(filter_var($data,FILTER_VALIDATE_URL)) {
            $output = $data;
        }
    }
    if($data_type == "ip") {
        if(filter_var($data,FILTER_VALIDATE_IP)) {
            $output = $data;
        }
    }
    if($data_type == "array") {
        if(is_array($data)) {
            $data = array_map("htmlspecialchars",$data);
            $output = $data;
        }
    }
    if($data_type == "file_directory") {
        if(file_exists($data)) {
            $output = basename($data);
        }
    }
    if($output) {

    if($check_length) {

        if( ( ( mb_strlen($output) &gt;= $length_min ) &amp;&amp; ( mb_strlen($output) &lt;= $length_max ) ) === false) {
            $output = false;
        }
    }
    return $output;

    }
}

// call function 
$password = user_input_data(
    $_POST["password"],
    array(
        "length_min" =&gt; 8, "length_max" =&gt; 24 ,"data_type" =&gt; "string"
    )
);
I suggest you should use a configuration array like this:

 $config = [
      ip =&gt; FILTER_VALIDATE_IP,
      email=&gt; FILTER_VALIDATE_EMAIL
 ]


and simplify the code like this:

if(in_array($config, $data_type)) {
     if($filter_VAR($data, $config[$data_type]) {
          $output = $data;
     }
}



In your code, length is checked only if both min and max are set. Is it the expected behavior? In some cases, only min or max checks are required.
Generally, you should avoid repeating code, in favor of calling functions. This makes it more readable. Plus, you can create test cases for small functions with predictable results, rather that a big complicated thing.
With security I have no idea what this function is designed to protect against.