JMulligan Posted July 31, 2007 Share Posted July 31, 2007 I am looking for a function that deals with the various leaning/"smart" quotes that programs like Microsoft Word like to create, that in the course of inserting through a php script into a postgres database, come out as gibberish. For example an apostrophe comes out as ’. Ideally I'd like something that converts all known examples of "smart" quotes into their normal/nonsmart counterparts, and parses out any strange characters it does not recognize. I have played around with uft8_encode(), and the function listed below, but i am unable currently to prevent the broken characters from getting through. function fix_utf8($value) { $value = str_replace(array("\205", "\221", "\222", "\223", "\224", "\226", "\240", "\x97"), array("...", "'", "'", "\"", "\"", "-", " ", "-"), $value); $value = utf8_encode($value); return $value; } Quote Link to comment https://forums.phpfreaks.com/topic/62710-inserting-smart-quotes-into-a-postgres-database/ Share on other sites More sharing options...
Wildbug Posted July 31, 2007 Share Posted July 31, 2007 Search for it, either on this site or Google the entire known universe. If you search this site, you might find this topic. If you read that topic, you might find this link that helps you convert those evil quotes. Quote Link to comment https://forums.phpfreaks.com/topic/62710-inserting-smart-quotes-into-a-postgres-database/#findComment-312127 Share on other sites More sharing options...
JMulligan Posted July 31, 2007 Author Share Posted July 31, 2007 I'd like for my function to be able to submit into the database a large variety of characters. With the functions in the page you linked to characters like ó cause an error that don't even let the string get submitted. With my fix_utf8 function ó doesn't cause an error ("although it does return ó instead of ó). There anyway to handle all multi byte characters? Quote Link to comment https://forums.phpfreaks.com/topic/62710-inserting-smart-quotes-into-a-postgres-database/#findComment-312242 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.