Chapter 3 encoding issues
Published by Jeffrey February 9th, 2007 in The BookUPDATE: added encoding fix.
A few savvy readers have pointed out an issue with the final map in Chapter 3. The example in the book wasn’t complete and does require additional work to be a fully functional but…In the scripts that store the information to the server I was simply adding an entry to an XML file. What I failed to mention (and didn’t include in the example) was that the input needs to be properly encoded to utf8 format and properly escaped to prevent HTML tag injection. The storeMaker.php example listing:
$lat = (float)$_GET['lat'];
$lng = (float)$_GET['lng'];
$found = $_GET['found'];
$left = $_GET['left'];
$icon = $_GET['icon'];
have been updated to include the appropriate fixes:
$lat = (float)$_GET['lat'];
$lng = (float)$_GET['lng'];
$found = htmlspecialchars(strip_tags(utf8_encode($_GET['found'])));
$left = htmlspecialchars(strip_tags(utf8_encode($_GET['left'])));
$icon = htmlspecialchars(strip_tags(utf8_encode($_GET['icon'])));
As well, the header in storeMarker.php and retrieveMarkers.php should include the appropriate charset.
header('Content-Type: text/xml;charset=UTF-8');
The map should now work as intended.




The code snippet provided in the post uses the right-single-quote (coded as HTML entity ’). When I copied & pasted this into my storeMarker script it caused an error. Using the apostrophe character, as used in the storemarker.php example listing, solved the problem. Perhaps the blog post should use ' in case someone else does a copy & paste.
Sorry to say but there is still a problem with my name, sorry. :-)
Tine Müller looks like this - Found Tine Müller
i have the same problem as Tine Müller, but in arabic encoding (the same concept)
my example is in the bottom left corner
Same problem here with Greek encode. Is there a way to use ISO insteed of UTF? thx.
How can i use the form.html file?
Yes, i found a solution!
can u post the solution poto
I’ve had the problem using German Umlauts, too.
Since I’m translating the book into German it was nasty.
Just put the lines
it got lost
in storeMarker.php, and retrieveMarkers.php and other HTML-headers:
Content-Type: text/xml;charset=UTF-8
I don’t understand the messages from Gerhard, sorry.
Are you saying that you have solved the problem and if so what need to be changed and exactly where?
The charset in the header is also required. I updated the post to reflect the changes. I think it’s all working now.
the last modification did solve the problem, but with removing the utf8_encode command used before
thanx alot
If I want to add a photo into the marker, what can I do?
I want to save the marker into a mysql server and save a reference of the location of the photo too.
Anybody has a suggestion for me?
Thank you
I have a problem when I tried to save it in Firefox 3…
XML Parsing Error…Not well-formed…
any idea on this?
thanks