Page 1 of 1

Bizarre characters on page - how to stop??

Posted: Sat Jun 14, 2008 8:11 pm
by scottrichardson
Hi all,

On ny site, my users can submit news articles and other content via forms which insert content into mysql.

When inserting text containing certain characters, it's replacing them with strange groups of characters.

Take a look, see the bits in red:

"Ibiza - the birthplace of modern dance music. 20 years on and the island remains an important catalyst for todayâ•?s hottest dance talents. This year, OceanLab, the project featuring Above & Beyond and singer/songwriter Justine Suissa spent several weeks holed up in a villa there finishing their debut album, â•?Sirens Of The Seaâ•?."

Now i know this has to do with text encoding. But I'm not sure how to overcome this.

Every time people add content to my site, I have to edit it.

I did find a function online somewhere, but it appears not to be working as it should.... or at all??

here is the function:

Code: Select all

function smarties($string) 
{ 
       /**
     *  ‘  8216  curly left single quote
     *  ’  8217  apostrophe, curly right single quote
     *  “  8220  curly left double quote
     *  ”  8221  curly right double quote
     *  —  8212  em dash
     *  –  8211  en dash
     *  …  8230  ellipsis
     */
    $search = array(
                    '&',
                    '"',
                    chr(212),
                    chr(213),
                    chr(210),
                    chr(211),
                    chr(209),
                    chr(208),
                    chr(201),
                    chr(145),
                    chr(146),
                    chr(147),
                    chr(148),
                    chr(151),
                    chr(150),
                    chr(133)
                    );
    $replace = array(
                    '&',
                    '"',
                    '‘',
                    '’',
                    '“',
                    '”',
                    '–',
                    '—',
                    '…',
                    '‘',
                    '’',
                    '“',
                    '”',
                    '–',
                    '—',
                    '…'
                    );
     
    return str_replace($search, $replace, $string); 
}
I'm sure someone has come across this before. Any suggestions would be greatly appreciated.

Kind regards,

Scott

Re: Bizarre characters on page - how to stop??

Posted: Sun Jun 15, 2008 5:33 am
by superdezign
Websites have a type of text encoding and databases have a type of text encoding. For example, this forum uses UTF-8. UTF-8 would be my personal recommendation, because ISO-8859-1 tends to have problems similar to this. Make sure that your website and your database agree in terms of text encoding.

Re: Bizarre characters on page - how to stop??

Posted: Sun Jun 15, 2008 8:21 am
by scottrichardson
Will do.

Actually, by switching to UTF- (I was in ISO) for my web pages, it has appeared to fix all of the characters except for a few, which now appear as diamonds with question marks in them. HOWEVER, I have not altered my database yet. It's currently in latin. I will switch the tables to UTF and see how that goes.

Thanks

Scott

Re: Bizarre characters on page - how to stop??

Posted: Sun Jun 15, 2008 12:35 pm
by adguru
Create a filter array and use it everytime. For example,

$x[0][0]="splchar"
$x[0][1]="text equivalent"

I hope this helps, most of the forums use this technique.

Re: Bizarre characters on page - how to stop??

Posted: Sun Jun 15, 2008 6:05 pm
by scottrichardson
Hi adguru, please excuse my lofi knowledge of arrays.. could you show me how I would fully implement that?

What the full code would be?

Scott