"I know I can run a PHP script to clean all the data, but there are a heck of a lot of entries, and that's going to take forever."
Yep, that is the right approach. Set up the script so it can run for a long time, blow up, and get restarted easily. I've cleaned up some bad stuff by walking through the data base tables in "auto_increment" order, echoing out the key for each row that I have cleaned. When the thing blows, I just take the last key from the prior execution and use that as the starting point for the next run.
The good news here is that your "stripslashes" algorithm will not mung the data so you can rerun it several times over with no danger.
You can shorten the run time by making a select on only the rows that contain slashes, so if the data is like this, you'll only get one record... Use MySQL LIKE to pick out these rows.
Bill Reilly
Joe Reilly
Mary O\'Reilly
Brian O'Reilly
Use mysql_real_escape_string()
You can use an iterative technique to strip out all the slashes. See code snippet.
Best of luck with it, ~Ray
Main Topics
Browse All Topics





by: jausionsPosted on 2009-03-08 at 12:48:58ID: 23830950
Have a look at the REPLACE() function [1]
efman/5.0/ en/string- functions. html#funct ion_replac e
// To replace \' into '
UPDATE myTable
SET myField = REPLACE(myField, '\\\'', '\'')
WHERE myField LIKE '%\\\''
// To replace \" into "
UPDATE myTable
SET myField = REPLACE(myField, '\\"', '"')
WHERE myField LIKE '%\\"'
[1] http://dev.mysql.com/doc/r