<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tampa Site Design &#187; textarea</title>
	<atom:link href="http://www.tampasitedesign.com/tag/textarea/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tampasitedesign.com</link>
	<description>Chronicles of Website Design</description>
	<lastBuildDate>Sun, 08 Aug 2010 19:36:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Line Breaks in Textarea with PHP</title>
		<link>http://www.tampasitedesign.com/line-breaks-in-textarea-with-php/</link>
		<comments>http://www.tampasitedesign.com/line-breaks-in-textarea-with-php/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 19:38:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[line breaks]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[textarea]]></category>

		<guid isPermaLink="false">http://www.tampasitedesign.com/?p=60</guid>
		<description><![CDATA[There seems to be a  lot of confusion surrounding line breaks. You&#8217;re probably familiar with this:
\r\n
This is a line break, right? Well it can be. It depends on if it&#8217;s processed as normal text or not.
Let&#8217;s say a user is submitting a form and in the textarea, they add some line breaks. Let&#8217;s say they [...]]]></description>
			<content:encoded><![CDATA[<p>There seems to be a  lot of confusion surrounding line breaks. You&#8217;re probably familiar with this:</p>
<p>\r\n</p>
<p>This is a line break, right? Well it can be. I<strong>t depends on if it&#8217;s processed as normal text or not.</strong></p>
<p>Let&#8217;s say a user is submitting a form and in the textarea, they add some line breaks. Let&#8217;s say they miss a field and  you have the form printing out it&#8217;s own POST values (so they don&#8217;t accidentally lose anything), like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;textarea cols=&quot;32&quot; rows=&quot;6&quot; name=&quot;description&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'description'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/textarea&gt;</pre></div></div>

<p>This is pretty simple, it&#8217;s just printing out the value of the posted description variable. But like I said a minute ago, if they had put line breaks in their textarea, their information will be posted in the textarea again, but it will look like this:</p>
<p>Information on Line 1\r\nInformation on Line 2</p>
<p>The problem here is that the \r\n is getting changed to normal text. To change it back, we replace it with itself, but with double quotes, returning it back to code as opposed to normal text. Here&#8217;s the final result:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;textarea name=&quot;description&quot; rows=&quot;6&quot; cols=&quot;32&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'\r\n'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'description'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/textarea&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.tampasitedesign.com/line-breaks-in-textarea-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

