When I first add a Greek character in, within the HTML form I set up for editing the site, I write it as a decimal character reference - for example:
α
But if I go back to edit the article again, it actually appears as the Greek letter (in this case a small alpha) within the HTML form.
If I save changes to the article and then check the live page once again, the character has been changed to something other than an alpha character. (In my case a box, but I believe that is part of another issue, many characters are not displaying correctly for me, likely an OS thing). The source code then shows it as an letter "a" with an accent mark on it, rather than the character reference:
α
Is this some kind of inherent problem with MySQL? Is there anything I can do about it? As it is, if I make any changes to existing articles I will have to remember if I used any non standard characters, and change them back to the correct decimal character reference before saving again.
As it really isn't easy to explain what happens letīs try by going through it one step at a time.
When I first add a Greek character in, within the HTML form I set up for editing the site, I write it as a decimal character reference - for example:α
The browser will treat that as the literal characters &, #, 9, 4, 5, ;. Character reference are only turned into their real character when the browser loads the page.
and then check it on the live page, and it seems ok,
The browser now sees the character reference and changes it into the real character.
But if I go back to edit the article again, it actually appears as the Greek letter (in this case a small alpha) within the HTML form.
This is basically the same as the previous step. The character reference is turned into the real character. If you submit the form you get the real character.
If I save changes to the article and then check the live page once again, the character has been changed to something other than an alpha character. (In my case a box, but I believe that is part of another issue, many characters are not displaying correctly for me, likely an OS thing). The source code then shows it as an letter "a" with an accent mark on it, rather than the character reference:α
which I had originally typed in.
The real character now gets send to the server and gets garbled if you use the wrong character set.
Solution
There are two solutions:
Example code
Use this code to see the problem/solution:
<form method=post>
<?php
echo $_POST['test'], '<br>';# Uncomment the following line to get it working ok.
#$_POST['test'] = htmlentities($_POST['test']);echo <<<END
<input type=text name=test value="$_POST[test]">
END;
?>
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-7">
</head>
<body>
<form method=post enctype="multipart/form-data" accept-charset="ISO-8859-7">
<?php
print $_POST['test'];echo <<<END
<input type=text name=test value="$_POST[test]">
END;
?></form></body></html>
BTW, you should use proper html not my poor excuse for it.
As you see this isnīt a problem of MySQL. It only appeared to be to you since you have a call to MySQL between repeated invocations of your script.
Hope this helps.
Andreas
I figured I'd have to go back to my original solution of remembering if I used any non standard characters, and change them back to the correct decimal character reference before saving again.
Then in one last attempt to understand this - where I have:
echo $article_result[article]; I just wrapped htmlentities around it like this:
echo htmlentities($article_result[article]); and OH MY GOD it worked! I didn't expect that, I thought it would be a lot more complicated!
Thanks!