Jump to content

Euro Apostrophes


kiss-o-matic

Recommended Posts

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

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

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

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.