Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/rekall/krisgale.com/wp-includes/formatting.php on line 74

recently, i could not for the life of me determine why two strings that should have compared as being equal simply refused to do so… that is, until i set up an alert box to display the underlying comparison character-by-character.

you’ll get different output from this script depending on whether you are viewing it from opera, safari, firefox, or internet explorer. the former two convert all instances of the non-breaking space html entity ( ) into its ascii character equivalent (#160)… the latter two leave the html as-is.

pay close attention:

  1. <html>
  2. <head>
  3. <title>string comparison</title>
  4. </head>
  5. <body>
  6. <pre>
  7. <span id="a">A&nbsp;b</span>
  8. <span id="b">a B</span>
  9. <script type="text/javascript">
  10. var x = document.getElementById("a").innerHTML;
  11. var y = document.getElementById("b").innerHTML;
  12. x = x.toLowerCase().replace('&nbsp;',' ');
  13. y = y.toLowerCase();
  14. document.writeln(x == y);
  15. x = x.replace('\xa0',' ');
  16. document.writeln(x == y);
  17. </script>
  18. </pre>
  19. </body>
  20. </html>