Jump to content

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.