[solved?] dirty hack for the Chat character encoding problem

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
b0n3m4n

[solved?] dirty hack for the Chat character encoding problem

Post by b0n3m4n »

Hi!

I tried for hours to find a decent solution to the Chat character encoding problem but without ajax experience I am totally lost. Since I need a working chat now I decided to implement a really ugly hack to circumvent the problem for now.

Here you go if you have the same problem and don't mind the bad style:

Insert this into Chat.module.php at line 327 right after $chatline=utf8_encode($chatline);:

Code: Select all

//dirty hack *shudder*
    $chatline = preg_replace('/ä/','ä',$chatline);
    $chatline = preg_replace('/ö/','ö',$chatline);
    $chatline = preg_replace('/ü/','ü',$chatline);
    $chatline = preg_replace('/Ä/','Ä',$chatline);
    $chatline = preg_replace('/Ö/','Ö',$chatline);
    $chatline = preg_replace('/Ü/','Ü',$chatline);
    $chatline = preg_replace('/ß/','ß',$chatline);
//dirty hack end (thank God)
This only corrects German special characters (äöüÄÖÜß) so far.
If you want to complete the list for other characters go to the chat, send the character you want to the chat, and copy the resulting badly encoded characters. Add a line for each character to the code above. The syntax is like this:

$chatline = preg_replace('/Ã[CHAR]/','[HTML_CHAR]',$chatline);

where [CHAR] are the characters you copied from the chat window and [HTML_CHAR] is the corresponding html-character entity (full list here: http://www.w3.org/MarkUp/html3/latin1.html).

I hope there will be a decent solution to this problem in the near future, but for now, this will do.

Cerno
User avatar
Silmarillion
Dev Team Member
Dev Team Member
Posts: 483
Joined: Sun Jan 02, 2005 9:10 pm
Location: Denmark

Re: [solved?] dirty hack for the Chat character encoding problem

Post by Silmarillion »

Hi Cerno

As soon as I get home from vacation (in Florida right now) I'll look into the char-problems in Chat-module. And if I cannot find a "cleaner" solution I'll add your dirty hack ;-) hope tha's ok!

Best regards
Silmarillion
b0n3m4n

Re: [solved?] dirty hack for the Chat character encoding problem

Post by b0n3m4n »

I have no problem with that, although I don't think my code should be in there for good. If there is no cleaner solution we'll have to make do. If that's the case, please let me know and I'll try to include more than the German special characters.

I just realized that I could have optimized the hack by using arrays of strings instead of multiple regex calls. That's what you get for coding in the middle of the night.

Oh and no need to use regex anyhow, this is just a simple string replacement. So this should be more efficient:

Code: Select all

//slightly less dirty hack

    $badstrings = array("ä", "ö", "ü", "Ä", "Ö", "Ü", "ß");
    $goodstrings = array("ä", "ö", "ü", "Ä", "Ö", "Ü", "ß");

    $chatline = str_replace($badstrings, $goodstrings, $chatline);

//dirty hack end
Enjoy your vacation!
Cerno
Locked

Return to “Modules/Add-Ons”