<?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; Backwards compatibility</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>Using file_get_contents before v4.3.0</title>
		<link>http://www.php-scripts.com/20051107/58/</link>
		<comments>http://www.php-scripts.com/20051107/58/#comments</comments>
		<pubDate>Mon, 07 Nov 2005 20:09:44 +0000</pubDate>
		<dc:creator>TDavid</dc:creator>
		
		<category><![CDATA[Backwards compatibility]]></category>

		<category><![CDATA[How To]]></category>

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

		<guid isPermaLink="false">http://www.php-scripts.com/?p=58</guid>
		<description><![CDATA[One of the dangers of using newer PHP functions is that sometimes you&#8217;ll end up with people who are stuck on a shared host using an older version of PHP. In this case it&#8217;s helpful to have some backwards compatible functions. The category backwards compatability will deal with these situations.
file_get_contents has only been available in [...]]]></description>
			<content:encoded><![CDATA[<p>One of the dangers of using newer PHP functions is that sometimes you&#8217;ll end up with people who are stuck on a shared host using an older version of PHP. In this case it&#8217;s helpful to have some backwards compatible functions. The category backwards compatability will deal with these situations.</p>
<p>file_get_contents has only been available in PHP since 4.3.0. Here is how to make it backwards compatible to version 3.xx of PHP by using file and implode:</p>
<div class="codesnip-container" >
<div class="codesnip">&lt;?php<br />
<span class="co1">// PHP 4.3.0 or later </span><br />
<span class="re0">$page_source</span> = <a href="http://www.php.net/file_get_contents"><span class="kw3">file_get_contents</span></a><span class="br0">&#40;</span><span class="st0">&#8220;http://www.yourdomain.com/yourpage.html&#8221;</span><span class="br0">&#41;</span>;</p>
<p><span class="co1">// pre 4.3.0</span><br />
<span class="re0">$page_source</span> = <a href="http://www.php.net/implode"><span class="kw3">implode</span></a><span class="br0">&#40;</span><span class="st0">&#8221;</span>, <a href="http://www.php.net/file"><span class="kw3">file</span></a><span class="br0">&#40;</span><span class="st0">&#8220;http://www.yourdomain.com/yourpage.html&#8221;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
<span class="kw2">?&gt;</span></div>
</div>
<p>Now let&#8217;s say you wanted to make your own file_get_contents function for pre 4.3.0? Here&#8217;s what you would do:</p>
<div class="codesnip-container" >
<div class="codesnip">&lt;?php<br />
<span class="co1">// only use this in pre 4.3.0 PHP where file_get_contents is not available</span><br />
<span class="kw2">function</span> <a href="http://www.php.net/file_get_contents"><span class="kw3">file_get_contents</span></a><span class="br0">&#40;</span><span class="re0">$in</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; <span class="kw1">return</span>&nbsp; <a href="http://www.php.net/implode"><span class="kw3">implode</span></a><span class="br0">&#40;</span><span class="st0">&#8221;</span>, <a href="http://www.php.net/file"><span class="kw3">file</span></a><span class="br0">&#40;</span><span class="re0">$in</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
<span class="re0">$page_source</span> = <a href="http://www.php.net/file_get_contents"><span class="kw3">file_get_contents</span></a><span class="br0">&#40;</span><span class="st0">&#8216;http://www.yourdomain.com/yourpage.html&#8217;</span><span class="br0">&#41;</span>;<br />
<span class="kw2">?&gt;</span></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.php-scripts.com/20051107/58/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
