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!
Take a look at this nice cheat sheet, it'll come in handy farther down the road.
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.