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