{"id":50,"date":"2010-02-04T15:08:53","date_gmt":"2010-02-04T20:08:53","guid":{"rendered":"http:\/\/jamesroberts.name\/blog\/?p=50"},"modified":"2010-02-04T15:11:46","modified_gmt":"2010-02-04T20:11:46","slug":"wack-mac-newline-character-in-utf-8","status":"publish","type":"post","link":"https:\/\/jamesroberts.name\/blog\/2010\/02\/04\/wack-mac-newline-character-in-utf-8\/","title":{"rendered":"Wack Mac newline character in utf-8"},"content":{"rendered":"<p>So I had a user come to me with with an error with my WYSIWYG editor in our online website builder.  He would save his content, which he had pasted from OSX&#8217;s TextEdit program, then try to apply that content to his website.  I have a PHP function which escapes new lines and single quotes to make it compatible with inserting the content into a textarea for editing.  But, I had missed the Unicode (UTF-8) &#8220;line separator&#8221; (0xE2 0x80 0xA8), so Javascript was throwing the &#8220;Unterminated String Literal&#8221; error.  Anyway, after much angst, death, pain, hurting, and unfruitful googling, my co-worker found that UTF-8 has the &#8220;line separator&#8221; character.  He also found other weird newline characters for UTF-8.  Here is a list of the newline characters:<\/p>\n<ul>\n<li>&#8220;line separator&#8221;<\/li>\n<li>&#8220;page separator&#8221;<\/li>\n<li>&#8220;next line&#8221;<\/li>\n<\/ul>\n<p>Here is a link to a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Mapping_of_Unicode_characters#Other_Separators\" target=\"_blank\">Wikipedia Article<\/a> about it.<\/p>\n<p>To fix the problem, I updated my JavaScript escape function to include this new character.  You can see the new function below:<\/p>\n<pre lang=\"php\" line=\"1\">\r\nfunction jsesc($escString){\r\n\t$find = array( \"'\", '\u2019', \"\\n\", \"\\r\", chr(226).chr(128).chr(168), chr(226).chr(128).chr(169), chr(194).chr(133));\r\n\t$replace = array( \"\\\\'\", \"\\\\'\", \"\\\\n \", \"\\\\n\", \"\\\\n\", \"\\\\n\", \"\\\\n\");\r\n\treturn str_replace($find, $replace, stripslashes($escString));\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>So I had a user come to me with with an error with my WYSIWYG editor in our online website builder. He would save his content, which he had pasted from OSX&#8217;s TextEdit program, then try to apply that content to his website. I have a PHP function which escapes new lines and single quotes [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[13,61,12,62,11],"_links":{"self":[{"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/posts\/50"}],"collection":[{"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/comments?post=50"}],"version-history":[{"count":5,"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/posts\/50\/revisions"}],"predecessor-version":[{"id":55,"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/posts\/50\/revisions\/55"}],"wp:attachment":[{"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/media?parent=50"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/categories?post=50"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/tags?post=50"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}