{"id":524,"date":"2009-06-03T22:21:17","date_gmt":"2009-06-04T04:21:17","guid":{"rendered":"http:\/\/www.mooreds.com\/wordpress\/archives\/000524"},"modified":"2009-06-03T22:21:17","modified_gmt":"2009-06-04T04:21:17","slug":"flex-textareas-newlines-and-posting-to-a-unix-server","status":"publish","type":"post","link":"https:\/\/www.mooreds.com\/wordpress\/archives\/524","title":{"rendered":"Flex textareas, newlines and posting to a unix server"},"content":{"rendered":"<p>I was working on a flex app and wanted to post the contents of a <a href=\"http:\/\/livedocs.adobe.com\/flex\/3\/langref\/mx\/controls\/TextArea.html\">flex textarea<\/a> to a php script on a unix server, among other fields.\u00a0 This is easy to do with the <a href=\"http:\/\/livedocs.adobe.com\/flex\/3\/langref\/flash\/net\/URLRequest.html\">URLRequest<\/a>.\u00a0 The php script on the server then parsed the form fields.\u00a0 In particular, it split the textarea&#8217;s contents on the newline.<\/p>\n<p>When I first tried this, the php script only found one record, no matter how big the textarea content.\u00a0 After haivng the php script write the content to a file, it was clear why.\u00a0 The flex app was sending the textarea with Windows line endings.\u00a0 I&#8217;ve never experienced this particular issue before.\u00a0 I tested a plain old HTML form, and somewhere the newlines are converted from Windows to unix (for <a href=\"http:\/\/en.wikipedia.org\/wiki\/Newline\">more than you ever wanted to know about the humble newline, consider wikipedia<\/a>.)<\/p>\n<p>Regardless, the answer was to make sure that wordwrap was set to false, and run a regular expression on the content of the textarea before sending it.\u00a0 From <a href=\"http:\/\/blog.flexexamples.com\/2008\/12\/16\/replacing-carriage-returns-and-line-feeds-with-newline-characters-using-regular-expressions\/ \">the comments on this blog post<\/a>:<a href=\"http:\/\/blog.flexexamples.com\/2008\/12\/16\/replacing-carriage-returns-and-line-feeds-with-newline-characters-using-regular-expressions\/ \"><br \/>\n<\/a><\/p>\n<p><code>loremTEXT2 = loremTEXT.replace(\/[\\r\\n]+\/g, \u201c\\n\u201d);<\/code><\/p>\n<p>[tags]the humble newline, flex, textarea[\/tags]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was working on a flex app and wanted to post the contents of a flex textarea to a php script on a unix server, among other fields.\u00a0 This is [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36,37],"tags":[],"class_list":["post-524","post","type-post","status-publish","format-standard","hentry","category-ria","category-tips"],"_links":{"self":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/524","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/comments?post=524"}],"version-history":[{"count":0,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/524\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/media?parent=524"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/categories?post=524"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/tags?post=524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}