XHTML, PHP, MySQL, IE and mdash character
I have a problem with mdash character (—, or Alt+0151).
Thing is I have a page with dtd like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
I also have a form (shortened version):
<form name="dep_new" action="whatever.php" method="post">
<input class="mandatory" id="dname" type="text" name="dname" value="<?php echo $department->name; ?>"/>
</form>
It is working with PHP 5.2 and MySQL 5.1 to store value of that input.
Now, when I work with any other browse but IE and input an mdash character into this field (by typing it Alt+0151) I get a proper long dash. It saves and retrieves from database with no problem.
However when I try to save it using IE9 I get the following:
Typing: Test—Test
After save and refresh: Test—Test
In other browsers I see: Test�Test
Becasue this is a departmnet name it is being displayed on another page and the results I get are : In IE: TestTest Other browsers: Test[a thing I cant post here - a square with 00 and 97 in it]Test
This square thing looks like this:
----
|00|
|97|
----
However if I do the same in say FF or Chrome, it displays fine in IE page as well while in IE input it shows:
开发者_如何学PythonTest—Test
Any attempt to encode/decode fails. However if I change dtd to:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN>
It all works fine in all browsers...
Any thoughts?
There is no Em-dash in standard Ascii table or ISO 8859-1 character set, it is available in Windows-1252 charset as 0x97 but this is a windows only standard. It is also available as unicode character U+2014 so you'd better use UTF-8 encoding for your pages if you want to safely use em-dash. add this to your <head>
:
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
Looks like you need a call to htmlentities when you echo out the name:
<input class="mandatory" id="dname" type="text" name="dname"
value="<?php echo htmlentities($department->name) ?>"/>
精彩评论