My problem involves searching a MySQL table for a list of matching city names given an initial search string with the purpose of handling special characters such ö, etc that are encoded with an html entity (ö).
Example:
There is a table called ‘cities’. The column for the city name is called ‘name’. There are two cities Hamberg (id 1) and Hämeenlinna (id 2) stored as Hämeenlinna.
Someone searches using the string “Ham”. A standard query such as
SELECT id, name FROM cities WHERE name LIKE '%Ham'
will only return the first one.
I have a regex that parses out the character from the entity but it’s implemented in PHP and is provided below for completeness.
preg_replace("/&(.).*;/", '$1', $city_name);
Is there a query to include the majority of the single characters that have entities?
You shouldn’t use HTML character references in the database. Instead you should choose the right encoding and collation and store the data in plain text.