Forum Moderators: coopster

Message Too Old, No Replies

Writing german Umlaut to a text file?

Result is strange Characters like?÷?¸?

         

rector

10:13 am on Jun 19, 2003 (gmt 0)

10+ Year Member



Hi,
I put german Umlaut like ÄäÖöÜü or ß in a MySQL Database. I read them out via php and they get displayed alright on a webpage.
However if I try to write them to a plain text file (with the fputs-function) for later processing I get those strange characters.

I am using php 4.3.1 and the settings in php.ini are
default_mimetype = "text/html"
default_charset = "iso-8859-1"

Any help is welcome.

bird

1:03 pm on Jun 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Whatever software you use for your "later processing" doesn't treat them according to iso-8859-1. Especially on Windows, you may need to convert the binary representation of those characters into some other character set.

rector

2:48 pm on Jun 19, 2003 (gmt 0)

10+ Year Member



I use different text editors and also MS Excel to look at the file after writing it from php and it all looks the same, just some strange characters. btw. that's on a Mac running OS X 10.2.4, it works all right on Windows 2000 Professional, but MacOSX is the desired platform.
Any clue on how to convert the characters to another character set?

Thanks in advance.

Helmut

bird

10:56 am on Jun 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Interesting. I'd have expected OS X to use iso-8859-1, not Windows. Maybe they inherited the custom character sets from the old MacOS.

The way to convert this depends on your (programming) language, and I don't have a clue about PHP.

With Python, I'd probably go through Unicode:

text1 = 'Näherungslösung'
utext = unicode(text1, 'iso-8859-1')
text2 = utext.encode('whatever-charset-OS-X-is-using')

Maybe you can figure out something equivalent for PHP... ;)

LeClair

2:58 pm on Jun 27, 2003 (gmt 0)

10+ Year Member



Does
htmlentities(string)
help you?
Which makes ä out of ä

antizwerg

3:46 pm on Jun 27, 2003 (gmt 0)

10+ Year Member



Mischief just pointed me to:

[php.net ]

to convert into different encodings.

Any idea which encoding and/or locale is used on your mysql server?

Timotheos

3:54 pm on Jun 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think the culprit is the difference in the MAC vs Windows. See [www1.tip.nl...]

So I think your best bet is to go with Unicode. The utf8_encode should be a good function for your needs.

rector

3:05 pm on Jun 28, 2003 (gmt 0)

10+ Year Member



Thank you folks,

due to your help I got the problem solved with the preg_replace function

// Character Set change from ISO 8859-1 to Mac-Roman

$find = array("/Ä/","/ä/","/Ö/","/ö/","/Ü/","/ü/","/ß/");
$replace = array(chr(128),chr(138),chr(133),chr(154),chr(134),chr(159),chr(167));
$exportstring = preg_replace($find,$replace,$exportstring);

You were great, especially the link from Timotheos

Thanks again.

Helmut

[edited by: jatar_k at 4:50 pm (utc) on June 28, 2003]
[edit reason] once is enough thanks [/edit]

Sander

12:16 am on Jul 2, 2003 (gmt 0)

10+ Year Member



htmlspecialchars() will do fine too.

it makes a ä -> ä etc.

LeClair

11:42 am on Jul 2, 2003 (gmt 0)

10+ Year Member



htmlspecialchars() will do fine too.

No. You need htmlentities() for that

rector

6:21 pm on Jul 2, 2003 (gmt 0)

10+ Year Member



Hi,
neither htmlspecialchars() nor htmlentities changes the characters correctly for output OUTSIDE of html-documents, which is what I needed.
I had to output textfiles for later use as a data source for MS Word Serial-Letters.

Helmut

ams_david

2:18 pm on Aug 11, 2003 (gmt 0)

10+ Year Member



something like this maybe?


$txt = ereg_replace ("ä", "ae", $txt);
$txt = ereg_replace ("ö", "oe", $txt);
$txt = ereg_replace ("ü", "ue", $txt);
$txt = ereg_replace ("ß", "ss", $txt);
$txt = ereg_replace ("Ä", "Ae", $txt);
$txt = ereg_replace ("Ö", "Oe", $txt);
$txt = ereg_replace ("Ü", "Ue", $txt);