Chapter 3 encoding issues

UPDATE: 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.


14 Responses to “Chapter 3 encoding issues”  

  1. 1 Drew

    The code snippet provided in the post uses the right-single-quote (coded as HTML entity &#8217). 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 &#39 in case someone else does a copy & paste.

  2. 2 Tine Müller

    Sorry to say but there is still a problem with my name, sorry. :-)

    Tine Müller looks like this - Found Tine Müller

  3. 3 ahmed

    i have the same problem as Tine Müller, but in arabic encoding (the same concept)

    my example is in the bottom left corner

  4. 4 poto

    Same problem here with Greek encode. Is there a way to use ISO insteed of UTF? thx.

  5. 5 poto

    How can i use the form.html file?

  6. 6 poto

    Yes, i found a solution!

  7. 7 ahmed

    can u post the solution poto

  8. 8 Gerhard

    I’ve had the problem using German Umlauts, too.

    Since I’m translating the book into German it was nasty.

    Just put the lines

  9. 9 Gerhard

    it got lost

    in storeMarker.php, and retrieveMarkers.php and other HTML-headers:

    Content-Type: text/xml;charset=UTF-8

  10. 10 Tine Müller

    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?

  11. 11 Jeffrey

    The charset in the header is also required. I updated the post to reflect the changes. I think it’s all working now.

  12. 12 ahmed

    the last modification did solve the problem, but with removing the utf8_encode command used before

    thanx alot

  13. 13 marcello

    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

  14. 14 darkforce

    I have a problem when I tried to save it in Firefox 3…
    XML Parsing Error…Not well-formed…
    any idea on this?

    thanks


Buy Our Books!

(Here's Why) PHP book Rails book DOM book mashups book