kiss-o-matic Posted January 10, 2009 Share Posted January 10, 2009 This is driving me nuts. I have an English client that will be putting in text copied and pasted from UK English (and other Euro) sources. They like to quote text ‘like this’. This is how I get rid of a normal apostrophe. $txt = preg_replace( "/\'/", "\\'", $txt ); The below snippet doesn't work. $txt = preg_replace( "/\‘/", "\\'", $txt ); $txt = preg_replace( "/\’/", "\\'", $txt ); In fact, preg_match doesn't catch these goofy guys (which aren't appart of ISO-8859-1 I see, but are used anyway). Usually I wouldn't care, but MySQL chokes on these. It doesn't treat it as a quotation mark, but it will stop inputting right then and there. The only text that makes it into the database is up to that point. Annoying, no? Link to comment https://forums.phpfreaks.com/topic/140301-euro-apostrophes/ Share on other sites More sharing options...
kenrbnsn Posted January 10, 2009 Share Posted January 10, 2009 Those are call "smart quotes" -- they are a Microsoft invention... This routine should work: <?php function convert_smart_quotes($string) { $search = array(chr(145), chr(146), chr(147), chr(148), chr(151)); $replace = array("'", "'", '"', '"', '-'); return str_replace($search, $replace, $string); } ?> I found it at Convert Smart Quotes with PHP Ken Link to comment https://forums.phpfreaks.com/topic/140301-euro-apostrophes/#findComment-734148 Share on other sites More sharing options...
kiss-o-matic Posted January 11, 2009 Author Share Posted January 11, 2009 Damn you Microsoft! And thank you kenrbnsn, I will give this a shot! Link to comment https://forums.phpfreaks.com/topic/140301-euro-apostrophes/#findComment-734387 Share on other sites More sharing options...
Mchl Posted January 11, 2009 Share Posted January 11, 2009 Just wondering... do ASP, MSSQL and other MS platforms manage to parse those quotes without any extra work? Thinks a little... Heck... MS Access allows just about any characters in column names (never mind that connecting to it from PHP is pain in the rear end then). Link to comment https://forums.phpfreaks.com/topic/140301-euro-apostrophes/#findComment-734401 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.