Jump to content

Inserting smart quotes into a postgres database.


JMulligan

Recommended Posts

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;

}

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.