<?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>SoftLayer Blog &#187; interpreted</title>
	<atom:link href="http://blog.softlayer.com/tag/interpreted/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.softlayer.com</link>
	<description>A Behind the Scenes Look at the Best Hosting Provider in the World</description>
	<lastBuildDate>Wed, 15 May 2013 15:33:34 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.1</generator>
		<item>
		<title>&#8216;What\&#8217;s with These &#8220;Quote&#8221; Things?&#8217;</title>
		<link>http://blog.softlayer.com/2011/whats-with-these-quote-things/</link>
		<comments>http://blog.softlayer.com/2011/whats-with-these-quote-things/#comments</comments>
		<pubDate>Wed, 12 Jan 2011 15:45:50 +0000</pubDate>
		<dc:creator>Phil Jackson</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[SoftLayer]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[developers]]></category>
		<category><![CDATA[format]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[interpreted]]></category>
		<category><![CDATA[literal]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/2011/</guid>
		<description><![CDATA[&#8216;We\&#8217;ve&#8217; . &#8220;all $een&#8221; . &#8216;this&#8217; . $problem . &#8216;before&#8217; . $and->it . ((1==1) ? &#8216;seems&#8217; : &#8216;dosen\&#8217;t seem&#8217;) . sprintf(&#8216;about time to %s things&#8217;, &#8216;clarify&#8217;); PHP string handling can be a tough concept to wrangle. Developers have many options: single / double quotes, concatenation and various string manipulation functions. The choices you make have [...]]]></description>
			<content:encoded><![CDATA[<p>&#8216;We\&#8217;ve&#8217; . &#8220;all $een&#8221; . &#8216;this&#8217; . $problem . &#8216;before&#8217; . $and->it . ((1==1) ? &#8216;seems&#8217; : &#8216;dosen\&#8217;t seem&#8217;) . sprintf(&#8216;about time to %s things&#8217;, &#8216;clarify&#8217;);</p>
<p>PHP string handling can be a tough concept to wrangle. Developers have many options: single / double quotes, concatenation and various string manipulation functions. The choices you make have a significant impact on the readability and performance of your script. Let&#8217;s meet the line-up:</p>
<p><strong>The Literal</strong><br />
Single quotes are used to define a string whose contents should be taken literally. What this means is that PHP will not attempt to expand any content contained between the <code>' '</code>.  </p>
<p>This is the way to tell your favorite Hypertext Preprocessor, &#8220;That little guy? Don&#8217;t worry about that little guy.&#8221;</p>
<p>In most cases this is the de-facto standard for strings.  However, when a decent number of variables become involved it tends to become difficult to keep your quotes accounted for. When combining simple strings with variables and single quotes, the &#8220;<code>.</code>&#8221; operator is needed between each variable/string. That &#8220;<code>.</code>&#8221; is known as the concatenation operator.</p>
<p><em>Input:</em><br />
<code>$date = 'Yesterday';</code><br />
<code>$location = 'outside';</code><br />
<code>$item = array ( 'description' => 'lovely', 'name' => 'butterfly');</code><br />
<code>$content = $date . ' I went  ' . $location . ' and caught a ' . $item['description'] . ' ' . $item['name'];</code></p>
<p><em>Output:</em> Yesterday I went outside and caught a lovely butterfly</p>
<p><strong>The Interpreted</strong><br />
Using double quotes will cause PHP to look a little closer into the string to find anywhere it can &#8220;read between the lines.&#8221; Variables and escape characters will be expanded, so you can reference them inline without the need for concatenation. This can be useful when creating strings which include pre-defined variables.</p>
<p><em>Input:</em><br />
<code>$file = 'example.jpg'</code><br />
<code>$content = "&lt;a href=\"http://www.example.com/$file\"&gt;$file&lt;/a&gt;"</code></p>
<p><em>Output:</em> &lt;a href=&#8221;http://www.example.com/example.jpg&#8221;&gt;example.jpg&lt;/a&gt;</p>
<p>In previous versions of PHP there was a significant performance difference between the use of single v. double quotes. In later versions performance variations are negligible. The decision of one over the other should focus on feature and readability concerns.</p>
<p><strong>The Thoughtful</strong><br />
Unlike single and double quotes, the <code>sprintf</code> function comes to the table with a few cards up its sleeve. When provided with a formatting &#8220;template&#8221; and arguments, <code>sprintf</code> will return a formatted string.</p>
<p><em>Input:</em><br />
<code>$order = array ( 'item' => 'RC Helicopters', 'status' => 'pending');</code><br />
<code>$content = sprintf('Your order of %s is currently %s', $order['item'], $order['status']);</code></p>
<p><em>Output:</em> Your order of RC Helicopters is currently pending</p>
<p>When constructing a complex string such as  XML documents, <code>sprintf</code> allows the developer to view the string with placeholders rather than a mish-mash of escaped quotes and variables.   In addition <code>sprintf</code> is able to specify the type of variable, change padding/text alignment, and even change the order in which it displays the variables.</p>
<p>The debate over the most efficient method of string definition has raged for years and will likely continue ad infinitum. However, when the benchmarks show their performance as almost identical, it leaves you with one major question: What works the best for your implementation? Typically my scripts will contain all of the methods above, and often a combination of them.</p>
<p><code>print(sprintf('The %s important thing is that %s give them all a try and see for %s', 'most', 'you', 'yourself'));</code></p>
<p>-Phil</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2011/whats-with-these-quote-things/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
