Reputation: 5887
I have a mysql database that is UTF8 encoded. However, due to some previous conversion issues that I inherited, certain strings have been saved incorrectly to the database.
For example, £ should be saved as £, but in many places its been saved as something like £.
I have been able to track down all the records in the table that have been incorrectly encoded. Whats the easiest way for me to remove all the unncessary characters from this varchar database field?
I've tried preg_replace in php, but this doesnt seem to actually do anything.
return preg_replace("[^A-Za-z0-9£]", "", $string);
Upvotes: 2
Views: 136
Reputation: 1532
What is being returned from that preg_replace call, an unaffected string or NULL? If it's null, then an error has occured according to preg_replace manual . Other than the missing delimiters that @AndreKR posted, it looks fine to me (tested with the string £
)
Upvotes: 0
Reputation: 33658
You must enclose the regex in delimiters:
return preg_replace("/[^A-Za-z0-9£]/", "", $string);
Upvotes: 2