Forum Moderators: coopster

Message Too Old, No Replies

Why when I do <? echo 'ö'; ?> it outputs š

Charset problem?

         

kazisdaman3

2:14 am on Mar 6, 2008 (gmt 0)

10+ Year Member



I have tried several days on this now and haven't an extremely hard time to just get simple special characters to work correctly.

How come when I do

<? echo 'ö'; ?> it outputs š

--

I've tried htmlspecialchars() it, htmlentities() it, and everything what am I doing wrong here, I even tried changing the <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> in the head, and that didn't do anything either.

bkeep

2:34 am on Mar 6, 2008 (gmt 0)

10+ Year Member



echo "&ouml;"

best regards,
Brandon

kazisdaman3

2:42 am on Mar 6, 2008 (gmt 0)

10+ Year Member



Thanks Brandon,

That works, but sorry I should been a little bit more clear. I'm taking to take in that variable. from Mysql.

---

$var = 'ö';

echo $var;

prints out š

---

It's almost like PHP doesn't understand: ö

and then trying to do like

$var = 'ö';
echo htmlentities($var);

still outputs š

--

Any ideas?

Esqulax

10:28 am on Mar 6, 2008 (gmt 0)

10+ Year Member



hows about:

$var = "&ouml;"

echo $var;

or if your funny o is being stored in the database, store it as &ouml;
then $var=$row['funny_o_coloumn'];
(based on circumstantial evidence)

Failing that, i'd go straight to a foreign language PHP site/forum where that letter gets used more often in the native language for names and suchlike.

[edited by: Esqulax at 10:30 am (utc) on Mar. 6, 2008]

deMorte

2:08 pm on Mar 6, 2008 (gmt 0)

10+ Year Member



I use the same charset and have no problems with any of the characters with umlaut (ö,ä,ü) even without any quotes. Maybe you could try using all of these symbols in a longer string and looking what comes out? Could your server setup have something to do with this problem? I am using server that is in Scandinavia and it probably has been configured with these characters in mind.
If you find out the reason for this strange behavior, please do share it. This might be a problem I could be facing some time as my pages are loaded with ö's and ä's.

jatar_k

2:15 pm on Mar 6, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



check your charset in your html page, as you did but try some others

if it's coming from mysql then you should look at the charset for mysql

php doesn't really care, it just shows the data it has, the browser/html control how it is displayed. Have you ever swapped charsets, saved, reloaded, you can get the chars to turn into all sorts of things. Is php changing the data, of course not, but the browser is interpreting it differently.

kazisdaman3

8:14 am on Mar 7, 2008 (gmt 0)

10+ Year Member



Storing ö, in the MYSQL db like &ouml;

seems like a backwards way correct, I mean that would work but it doesn't seem natural at all.

jatar_k, "hp doesn't really care, it just shows the data it has,"

Thats what I don't understand tho, even if we remove mysql from the equation:

$var = 'ö';

echo $var;

prints out š

--

It seems like php doesn't recognize that data. Php not recognizing the symbol ö at all? Because I can't even set =ö by itself, and then call it agian with php, it changes to š.

Its almost like PHP thinks ö = š, but š is it's own special character but itself?

Is there like a function I need to force charset on php to recognize the ö

jatar_k

1:28 pm on Mar 7, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



search for some extended ascii charts and take a look at the special chars and where they occur

looking at 2 charts right now and and &#154; is either š or Ü so, as I mentioned, it has nothing to do with php, the same data can be interpreted in various ways depending on charset.

when you paste in that ö it depends on what is actually sent.

kazisdaman3

12:53 am on Mar 8, 2008 (gmt 0)

10+ Year Member



Thanks jatar_k I'll take a look at this