<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.2.3" -->
<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/"
	>

<channel>
	<title>PHP-Scripts Blog &#187; Language</title>
	<link>http://www.php-scripts.com</link>
	<description>Writing about PHP scripting since 12/99. Learn something new every day.</description>
	<pubDate>Thu, 09 Oct 2008 14:17:07 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.3</generator>
	<language>en</language>
			<item>
		<title>How to strip off last two characters from string using substr</title>
		<link>http://www.php-scripts.com/20050913/5/</link>
		<comments>http://www.php-scripts.com/20050913/5/#comments</comments>
		<pubDate>Tue, 13 Sep 2005 18:54:09 +0000</pubDate>
		<dc:creator>TDavid</dc:creator>
		
		<category><![CDATA[Language]]></category>

		<category><![CDATA[Functions]]></category>

		<category><![CDATA[PHP 5.x]]></category>

		<category><![CDATA[PHP 4.x]]></category>

		<category><![CDATA[PHP 3.x]]></category>

		<guid isPermaLink="false">http://www.php-scripts.com/?p=5</guid>
		<description><![CDATA[substr comes in handy if you need to strip characters off the end of a string.

&#60;?php
$test_string = ‘item 1, item 2, item 3, ‘;
$test_string = substr&#40;$test_string,0,-2&#41;;
echo&#40;$test_string&#41;; // returns “item 1, item 2, item 3″ 
?&#62;

]]></description>
			<content:encoded><![CDATA[<p>substr comes in handy if you need to strip characters off the end of a string.</p>
<div class="codesnip-container" >
<div class="codesnip">&lt;?php<br />
<span class="re0">$test_string</span> = ‘item <span class="nu0">1</span>, item <span class="nu0">2</span>, item <span class="nu0">3</span>, ‘;<br />
<span class="re0">$test_string</span> = <a href="http://www.php.net/substr"><span class="kw3">substr</span></a><span class="br0">&#40;</span><span class="re0">$test_string</span>,<span class="nu0">0</span>,-<span class="nu0">2</span><span class="br0">&#41;</span>;<br />
<a href="http://www.php.net/echo"><span class="kw3">echo</span></a><span class="br0">&#40;</span><span class="re0">$test_string</span><span class="br0">&#41;</span>; <span class="co1">// returns “item 1, item 2, item 3″ </span><br />
<span class="kw2">?&gt;</span></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.php-scripts.com/20050913/5/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PHP Hello world!</title>
		<link>http://www.php-scripts.com/20050906/1/</link>
		<comments>http://www.php-scripts.com/20050906/1/#comments</comments>
		<pubDate>Wed, 07 Sep 2005 00:22:16 +0000</pubDate>
		<dc:creator>TDavid</dc:creator>
		
		<category><![CDATA[Language]]></category>

		<category><![CDATA[PHP 5.x]]></category>

		<category><![CDATA[PHP 4.x]]></category>

		<category><![CDATA[PHP 3.x]]></category>

		<guid isPermaLink="false">/?p=1</guid>
		<description><![CDATA[Welcome to the PHP-scripts blog. Though I&#8217;m not a huge fan of &#8216;Hello World&#8217; stuff, it seems that is where most things in the programming world start out. So here we go with examples using print and echo
Hello World using print statement

&#60;?php
print &#8216;Hello World!&#8217;;
?&#62;

Hello World using echo

&#60;?php 
echo &#8216;Hello World!&#8217;; 
?&#62;

What is the difference between [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to the PHP-scripts blog. Though I&#8217;m not a huge fan of &#8216;Hello World&#8217; stuff, it seems that is where most things in the programming world start out. So here we go with examples using <a href="http://us2.php.net/print">print</a> and <a href="http://us2.php.net/echo">echo</a></p>
<p><b>Hello World using print statement</b></p>
<div class="codesnip-container" >
<div class="codesnip">&lt;?php<br />
<a href="http://www.php.net/print"><span class="kw3">print</span></a> <span class="st0">&#8216;Hello World!&#8217;</span>;<br />
<span class="kw2">?&gt;</span></div>
</div>
<p><b>Hello World using echo</b></p>
<div class="codesnip-container" >
<div class="codesnip">&lt;?php <br />
<a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;Hello World!&#8217;</span>; <br />
<span class="kw2">?&gt;</span></div>
</div>
<p>What is the difference between print and echo?  <a href="http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40">print behaves like a function</a> and can be used in expressions like this, where echo cannot:</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="re0">$returns</span> = <a href="http://www.php.net/print"><span class="kw3">print</span></a> <span class="st0">&#8216;Hello World&#8217;</span>; <span class="co1">// $returns = 1 </span><br />
&nbsp;</div>
</div>
<p>echo is a tiny bit faster since it doesn&#8217;t set a return value. </p>
<p><b>Programming tips</b><br />
<i>Pick one format and stick to it</i>. For example, I like to use echo for echoing variable values like this:</p>
<div class="codesnip-container" >
<div class="codesnip"><a href="http://www.php.net/echo"><span class="kw3">echo</span></a><span class="br0">&#40;</span><span class="re0">$name</span><span class="br0">&#41;</span>; <span class="co1">// outputs value of string $name </span><br />
&nbsp;</div>
</div>
<p>But I prefer print for mixing text and variables like this:</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="re0">$name</span> = <span class="st0">&#8216;TDavid&#8217;</span>;<br />
<a href="http://www.php.net/print"><span class="kw3">print</span></a> <span class="st0">&#8220;My name is: $name&#8221;</span>; <span class="co1">// outputs: My name is TDavid </span><br />
&nbsp;</div>
</div>
<p>Since you can use or not use parenthesis, it&#8217;s important to determine a style that is consistent throughout coding projects to keep code easy to read.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.php-scripts.com/20050906/1/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

