Reputation: 1896
How can I make this regular expression replace spaces as well any non latin alpha numeric character?
preg_replace('/[^a-zA-Z0-9\s]/', '', $title)
Thanks a lot
Upvotes: 2
Views: 79
Reputation: 8700
I would just do:
<?php
preg_match_all('/[a-zA-Z0-9\s]/', $title, $out);
$ntitle = implode($out,'');
?>
EDIT: Briedis is right though, your regex works fine.
Upvotes: 1
Reputation: 17762
Everything looks ok, you just have to assing it to a variable!
$title = preg_replace('/[^a-zA-Z0-9\s]/', '', $title)
Upvotes: 3
Reputation: 887777
[^...]
matches anything but ...
.
\s
matches spaces.
You don't want it to not match spaces.
Upvotes: 3