Reputation: 47
I'm currently using the following to clean a string from symbols/unknown characters:
$title = preg_replace("/[^a-zA-Z0-9-]/", " ", $title);
However, I don't want to remove '&' from the string
Can someone help me out?
Thanks!
Upvotes: 2
Views: 8823
Reputation: 158160
the ^
at the start of a character class: [^... ]
means that all chars in that class should be excluded from matching. In your case this chars shouldn't be removed. So add &
to the class like this:
$title = preg_replace("/[^a-zA-Z0-9-&;]/", " ", $title);
Upvotes: 2
Reputation: 1337
Take a look at this nice cheat sheet, it'll come in handy farther down the road.
Upvotes: 3