How would I alter this function so that it allows single apostrophe's and hyphens:
function sanitize_string($s) {
$result = preg_replace("/[^a-zA-Z0-9]+/", " ", html_entity_decode($s, ENT_QUOTES));
return $result;
}
Just include the single apostrophe and the hyphen at the end of the range:
function sanitize_string($s) {
$result = preg_replace("/[^a-zA-Z0-9'-]+/", " ", html_entity_decode($s, ENT_QUOTES));
return $result;
}
Trying to get an answer to you as quick as I can.
I think you can just add them into the character class; possibly you'll need to escape them though.
Note: to use the -
be sure to put it at the end otherwise it will be considered a meta character.
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