Is there some way that I can remove an apostrophe from the middle of a string in PHP, but not at the beginning or end?
For example, I have a string like
'the cat jumped over the dog's lazy body'
The beginning and end quotes are in the string and are important, as they delineate the field in a record coming in from MySQLDump (created by BullZip, if that matters).
So in context, the record is similar to
INSERT INTO `SOMETABLE` () VALUES (1, '32295', NULL, 'RII20109', 'the cat jumped over the dog's lazy body', '11');
I need a way to escape (or remove) just the quote in the middle of the text, not at the beginning or end. I've tried all manner of str_replace options but feel I need a regex guru to help out, as I can't target the quote I want to change.
The overall process I use is to read the incoming file and chop it up with
$queries = explode(";", str_replace("\n\r", '', $sql));
and then execute each line with a MySQL query. That intermediate apostrophe is screwing things up.
Update
Sorry - in hindsight my question really wasn't very clear and has lead a few folk down the wrong path. The string I am working with is actually the whole line:
INSERT INTO `SOMETABLE` () VALUES (1, '32295', NULL, 'RII20109', 'the cat jumped over the dog's lazy body', '11');
not just a piece of it, as I misguidedly alluded to at the beginning. My bad. So as sin has suggested, there is really no way of knowing which apostrophe I should be working on, unless I pull the line apart even further (grab the VALUES () section somehow and then explode the contents and then use the techniques suggested on the individual fields. OMG! Don't think I can come at that!
BullZip is an MS Access to MySQL export program and yes, I believe that it should not be giving me this grief. It should be escaping the inter-field apostrophes, but there appears no setting to have it do so.
Another Update
To my significant embarrassment, after some more testing I have discovered that BullZip is handing quotes as it should, escaping with a slash. The offending character, upon closer scrutiny is not an apostrophe but one of those nasty MS Word "special" quotes (’), which of course I can fix with all the usual techniques. Sorry for wasting everybody’s time :(