I am trying to replace anything in the string that is not a letter, number, or dash "-".
How do I modify this line to include the dash?
$link = preg_replace('/[^a-z0-9]/', "", strtolower($_POST['link_name']));
Do I just insert it in there?
$link = preg_replace('/[^a-z0-9-]/', "", strtolower($_POST['link_name']));
You have to escape -
since it's a special character for regexes:
$link = preg_replace('/[^a-z0-9\-]/', '', strtolower($_POST['link_name']));
Just add -
to the end of the class ([^a-z0-9-]
).
-
has no special meaning at the end of a class. Alternatively, escape it with a backslash.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With