<?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>PHP Reference Book Blog &#187; backspace</title>
	<atom:link href="http://www.phpreferencebook.com/tag/backspace/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.phpreferencebook.com</link>
	<description>PHP Reference: Beginner to Intermediate PHP5</description>
	<lastBuildDate>Thu, 29 Sep 2011 03:50:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Formatting Characters</title>
		<link>http://www.phpreferencebook.com/tips/formatting-characters/</link>
		<comments>http://www.phpreferencebook.com/tips/formatting-characters/#comments</comments>
		<pubDate>Fri, 01 Aug 2008 13:31:43 +0000</pubDate>
		<dc:creator>Mario Lurig</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[backspace]]></category>
		<category><![CDATA[carriage return]]></category>
		<category><![CDATA[formatting characters]]></category>
		<category><![CDATA[new line]]></category>
		<category><![CDATA[newline]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[tab]]></category>

		<guid isPermaLink="false">http://www.phpreferencebook.com/?p=17</guid>
		<description><![CDATA[The rules and usage of formatting characters new line, carriage return, tab, and backspace within your PHP code including converting new line to the XHTML line break.]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve all seen them:</p>
<ul>
<li><strong>\n</strong> &#8211; new line</li>
<li><strong>\r</strong> &#8211; carriage return</li>
<li><strong>\t</strong> &#8211; tab</li>
<li><strong>\b</strong> &#8211; backspace</li>
</ul>
<p>But many wonder when to use them or more specifically, why they aren&#8217;t working as expected. So let&#8217;s address the basic usage and rules.</p>
<blockquote><p><em><strong>Rule #1:</strong> When using a formatting character in your code, it must be within &#8220;double quotations&#8221; otherwise it will be taken as a literal backslash and letter.</em></p></blockquote>
<p>When do you use it? When writing to a file with fwrite() or file_put_contents(), sending a text email with mail(), or when adding formatting to pre-populated data in the form element &lt;textarea&gt;.  Now, notice I made no mention of HTML output directly. While it&#8217;s possible to represent new line, tab, carriage return in HTML if it is within the preformatted tags &lt;pre&gt;&lt;/pre&gt;, in most cases these tags are not present and HTML will ignore these formatting characters.</p>
<blockquote><p><em><strong>Rule #2:</strong> Not all computer systems obey the formatting characters the same. When using \n (new line), also include a carriage return (\r) character.</em></p></blockquote>
<p>So what do you do if you have a paragraph, for instance submitted by a &lt;textarea&gt; form, that is preformatted and want it to display in the HTML with the \n (new line) breaks represented? That&#8217;s when you toss the string into the function nl2br(), which changes all \n to the xhtml line break &lt;br /&gt;.</p>
<p><strong>Example:</strong></p>
<p><code>echo nl2br("Hello\n\rWorld\n\r!!!");</code></p>
<p><strong>Results:</strong></p>
<p><code>Hello<br />
World<br />
!!!</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpreferencebook.com/tips/formatting-characters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

