Skip to content

Instantly share code, notes, and snippets.

@ramseyp
Created July 5, 2012 17:00
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ramseyp/3054876 to your computer and use it in GitHub Desktop.
Save ramseyp/3054876 to your computer and use it in GitHub Desktop.
Clean up malformed characters in WordPress database
## Run this in phpMyadmin
##
## Cleans up Posts table
UPDATE wp_posts SET post_content = REPLACE(post_content, '“', '“');
UPDATE wp_posts SET post_content = REPLACE(post_content, '”', '”');
UPDATE wp_posts SET post_content = REPLACE(post_content, '’', '’');
UPDATE wp_posts SET post_content = REPLACE(post_content, '‘', '‘');
UPDATE wp_posts SET post_content = REPLACE(post_content, '—', '–');
UPDATE wp_posts SET post_content = REPLACE(post_content, '–', '—');
UPDATE wp_posts SET post_content = REPLACE(post_content, '•', '-');
UPDATE wp_posts SET post_content = REPLACE(post_content, '…', '…');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'Â', '');
##
##
## Cleans up Comments
##
UPDATE wp_comments SET comment_content = REPLACE(comment_content, '“', '“');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, '”', '”');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, '’', '’');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, '‘', '‘');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, '—', '–');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, '–', '—');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, '•', '-');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, '…', '…');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, 'Â', '');
##
##
## Cleans up User Meta (descriptions)
##
UPDATE wp_usermeta SET meta_value = REPLACE(meta_value, '“', '“');
UPDATE wp_usermeta SET meta_value = REPLACE(meta_value, '”', '”');
UPDATE wp_usermeta SET meta_value = REPLACE(meta_value, '’', '’');
UPDATE wp_usermeta SET meta_value = REPLACE(meta_value, '‘', '‘');
UPDATE wp_usermeta SET meta_value = REPLACE(meta_value, '—', '–');
UPDATE wp_usermeta SET meta_value = REPLACE(meta_value, '–', '—');
UPDATE wp_usermeta SET meta_value = REPLACE(meta_value, '•', '-');
UPDATE wp_usermeta SET meta_value = REPLACE(meta_value, '…', '…');
UPDATE wp_usermeta SET meta_value = REPLACE(meta_value, 'Â', '');
@dhornbein
Copy link

You saved me a lot of work, thank you.

@mmizwicki
Copy link

This is gold! Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment