2

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);

2 Answers 2

2

You must enclose the regex in delimiters:

return preg_replace("/[^A-Za-z0-9£]/", "", $string);
Sign up to request clarification or add additional context in comments.

1 Comment

was in the process of that, so +1 for beating me
0

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 £)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.