I've got the following code:
<?php
$test = "xxxx..AAA?!";
echo $test."
";
$test = preg_replace("[^a-zA-Z0-9-]", "", $test);
echo $test."
";
?>
I want to delete all chars which aren't letters, numbers or a minus
What's my mistake?
delimiter is missing
$test = preg_replace('/[^a-zA-Z0-9-]/', '', $test);
echo $test . "
";
Additionally, I recommend using PHP_EOL
instead of " "
for newline characters.