1

I have some problems with removing numbers and special characters. I want to remove all numbers and special characters from the input. Here's my code :

$input = $_POST["input"];

function preprocessing($input){
    $input = trim(strtolower($input));
    $remove = '/[^a-zA-Z0-9]/s';
    $result = preg_split($remove, $input, -1, PREG_SPLIT_NO_EMPTY);
    for($i = 0; $i < count($resultl); $i++){
        $result[$i] = trim($result[$i]);
    }
    return $result;
}

String example : qwd qwd qwdqd123 13#$%^&*) ADDA ''''

Output : Array ( [0] => qwd [1] => qwd [2] => qwdqd123 [3] => 13 [4] => adda )

The numbers still appear on my string. How to solve this ? Thank you before.

brown26
  • 67
  • 1
  • 2
  • 9

1 Answers1

2

Check this

function clean($string) {
   $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.

   return preg_replace('/[^A-Za-z\-]/', '', $string); // Removes special chars.
}
Labradorcode
  • 371
  • 1
  • 12