<?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>Open Source Web &#187; PHP</title>
	<atom:link href="http://www.open-source-web.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.open-source-web.com</link>
	<description>Your open source for Development and Design</description>
	<lastBuildDate>Sun, 08 Jan 2012 10:21:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Twitter PHP and SimpleXML feed</title>
		<link>http://www.open-source-web.com/apis/twitter-php-and-simplexml-feed/</link>
		<comments>http://www.open-source-web.com/apis/twitter-php-and-simplexml-feed/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 20:45:04 +0000</pubDate>
		<dc:creator>Adi</dc:creator>
				<category><![CDATA[API's]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[simpleXML]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.open-source-web.com/?p=136</guid>
		<description><![CDATA[Just like the Google Charts API the Twitter API can be super simple. Twitter uses a few different XML feeds to send and receive data from a given user, some feeds require a user name and password supplied through Curl but a few are publicly available to all. This example will use the built in [...]]]></description>
			<content:encoded><![CDATA[<p>Just like the <a href="http://www.open-source-web.com/php/google-charts-example/">Google Charts API</a> the Twitter API can be super simple. Twitter uses a few different XML feeds to send and receive data from a given user, some feeds require a user name and password supplied through Curl but a few are publicly available to all.</p>
<p>This example will use the built in SimpleXML functions which come with PHP5, this is a much faster and easier way to using alternative readers such as simplePie or anything else you might come across. As far as it goes I don&#8217;t think SimpleXML gets enough coverage so I am happy to put it to some use for this example.</p>
<p>Keeping it basic</p>
<p>&lt;?php</p>
<p>$xml = simplexml_load_file(&#8220;http://twitter.com/statuses/user_timeline/adi182.xml?count=2&#8243;);<br />
if($xml){<br />
echo &#8216;&lt;h3&gt;&lt;a href=&#8221;http://www.twitter.com/adi182&#8243;&gt;Latest Tweets&lt;/a&gt;&lt;/h3&gt;<br />
&lt;ul&gt;&#8217;;<br />
foreach($xml-&gt;status as $tweet){<br />
$description = $tweet-&gt;text;<br />
echo &#8216;&lt;li&gt;&#8217;.$description.&#8217;&lt;/li&gt;&#8217;;<br />
}<br />
echo &#8216; &lt;/ul&gt;&#8217;;<br />
}<br />
?&gt;</p>
<p>So there you have it, the super simple example on putting a Twiter feed on your website.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.open-source-web.com/apis/twitter-php-and-simplexml-feed/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Google Charts Example</title>
		<link>http://www.open-source-web.com/php/google-charts-example/</link>
		<comments>http://www.open-source-web.com/php/google-charts-example/#comments</comments>
		<pubDate>Sat, 07 Mar 2009 18:14:03 +0000</pubDate>
		<dc:creator>Adi</dc:creator>
				<category><![CDATA[API's]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[chart]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[google]]></category>

		<guid isPermaLink="false">http://www.open-source-web.com/?p=117</guid>
		<description><![CDATA[API&#8217;s are becoming more popular on the web as many of the big online companies such as Google, Yahoo and Facebook offer there own open source code for web developers to use freely and easily. To begin with I am going to go through how to use the Charts Basics API from Google. This is [...]]]></description>
			<content:encoded><![CDATA[<p>API&#8217;s are becoming more popular on the web as many of the big online companies such as Google, Yahoo and Facebook offer there own open source code for web developers to use freely and easily.</p>
<p><img src="http://chart.apis.google.com/chart?chs=250x100&amp;chd=t:10,80,35,10&amp;cht=lc&amp;chl=wk1|wk2|wk3|wk4" alt="Google Charts Basics" /></p>
<p>To begin with I am going to go through how to use the Charts Basics API from Google. This is an extremely easy one to start off with as you don&#8217;t require an API key or to install anything, you don&#8217;t even need a dynamic server side script to get some nice results.</p>
<p>For this example I am going to jazz it up with a bit of PHP using an associative array but you can easily replace this with a database or XML feed.</p>
<p>To call a chart we use the query string linking to the API which will end up looking something like this.</p>
<pre id="line1">&lt;<span class="start-tag">img</span><span class="attribute-name"> src</span>=<span class="attribute-value">"http://chart.apis.google.com/chart?chs=250x100&amp;amp;chd=t:10,80,35,10&amp;amp;cht=lc&amp;amp;chl=wk1|wk2|wk3|wk4"
</span><span class="attribute-name">alt</span>=<span class="attribute-value">"Sample chart" </span><span class="error"><span class="attribute-name">/</span></span>&gt;</pre>
<p>To generate this dynamicaly I used the following code</p>
<pre class="php" name="code">$arr = array();

$arr['Jan']['wk1'] = 10;
$arr['Jan']['wk2'] = 80;
$arr['Jan']['wk3'] = 35;
$arr['Jan']['wk4'] = 10;

$chart= 'http://chart.apis.google.com/chart?';
$chartsize = 'chs=250x100';
$type = "cht=lc";
$vals = 'chd=t:';
$keys = 'chl=';
$alt = "January";

foreach( $arr['Jan'] as $key =&gt; $value){
	$vals .= $value.',';
	$keys .= $key.'|';
	}</pre>
<p>And Lastly to pull all the code together.</p>
<pre class="php" name="code">
&lt;img src="&lt;? echo $chart;?&gt;
&lt;? echo $chartsize;?&gt;
&amp;amp;&lt;? echo substr("$vals", 0, -1);?&gt;
&amp;amp;&lt;? echo $type;?&gt;
&amp;amp;&lt;? echo substr("$keys", 0, -1);?&gt;"
alt="Sample chart" /&gt;
</pre>
<p>To develop this example further use the official documentation available here <a title="Google Chart Basic" rel="nofollow" href="http://code.google.com/apis/chart/" target="_blank">Google Chart Basic</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.open-source-web.com/php/google-charts-example/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Random Banner with PHP</title>
		<link>http://www.open-source-web.com/php/random-banner-with-php/</link>
		<comments>http://www.open-source-web.com/php/random-banner-with-php/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 22:26:15 +0000</pubDate>
		<dc:creator>Adi</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[banners]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[random]]></category>

		<guid isPermaLink="false">http://www.open-source-web.com/?p=103</guid>
		<description><![CDATA[This is a quick tutorial which shows how easy it is to make a random banner script with PHP. We will use a PHP array of images which is populated by a given directory and select a random index from the array to be the banner. For this example I have chosen to list the [...]]]></description>
			<content:encoded><![CDATA[<p>This is a quick tutorial which shows how easy it is to make a random banner script with PHP. We will use a PHP array of images which is populated by a given directory and select a random index from the array to be the banner.</p>
<p>For this example I have chosen to list the files from a directory as this will keep the script fairly dynamic without the need of a database. The script could be easily modified to use a database but we can come back to that later on if we need to.</p>
<p>To start off all you will need is a folder with several banners and a page to display them on.</p>
<p>$dir will be the directory you have created to grab the images from, it is important to make sure this folder only contains banners.<br />
$banners will be the array of images found in the given folder.</p>
<pre class="php" name="code">

 $banners = array();
  $dir = 'res/banners/';
  if ($handle = opendir($dir)) {
  while (false !== ($file = readdir($handle))) {
  if($file != &quot;.&quot; &amp;&amp; $file != &quot;..&quot;){
  $banners[] = $file;
  }
  }
  closedir($handle);
  }

  $rand = array_rand($banners,1);
  echo &quot;&lt;img src='&quot;.$dir.$banners[$rand].&quot;' alt='banner'/&gt;&quot;;   
</pre>
<p>The code above uses a few handy built in PHP functions:<br />
opendir()<br />
readdir()<br />
array_rand()<br />
print_r()</p>
]]></content:encoded>
			<wfw:commentRss>http://www.open-source-web.com/php/random-banner-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fix Canonical URL with link rel=&#8221;canonical&#8221; in PHP</title>
		<link>http://www.open-source-web.com/seo/fix-canonical-url-with-link-relcanonical-in-php/</link>
		<comments>http://www.open-source-web.com/seo/fix-canonical-url-with-link-relcanonical-in-php/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 20:32:54 +0000</pubDate>
		<dc:creator>Adi</dc:creator>
				<category><![CDATA[SEO]]></category>
		<category><![CDATA[Canonical]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[fix]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[tag]]></category>

		<guid isPermaLink="false">http://www.open-source-web.com/?p=83</guid>
		<description><![CDATA[Recently the major search engines have worked together to help fix one of the biggest problems in SEO, The canonical URL. With this quick fix all you need to do is add a tag to the &#60;head&#62; section of the page and search engines will use this as an anchor to index the page. since [...]]]></description>
			<content:encoded><![CDATA[<p>Recently the major search engines have worked together to help fix one of the biggest problems in SEO, The canonical URL. With this quick fix all you need to do is add a tag to the &lt;head&gt; section of the page and search engines will use this as an anchor to index the page.</p>
<p>since it is still fairly new we don&#8217;t know how it will work in the long run and if there are any side effects such as the pagerank not transferring.</p>
<p>The new tag looks like this</p>
<p align="center"><strong><code>&lt;link rel="canonical" href="http://www.open-source-web.com/"&gt;</code></strong></p>
<p>But nothing can be that easy, obviously with a large site you wouldn&#8217;t want to write that out for a million pages so here is the PHP code to make it work.</p>
<pre name="code" class="php">

$thispage = "http://www.";
$thispage .= $_SERVER["SERVER_NAME"];
$thispage .= $_SERVER["PHP_SELF"];
if($_SERVER["QUERY_STRING"]){$thispage .= "?".$_SERVER["QUERY_STRING"];}

&lt;link rel="canonical" href="&lt;? echo $thispage;?&gt;"&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.open-source-web.com/seo/fix-canonical-url-with-link-relcanonical-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shorthand boolean IF with PHP</title>
		<link>http://www.open-source-web.com/php/shorthand-boolean-if-with-php/</link>
		<comments>http://www.open-source-web.com/php/shorthand-boolean-if-with-php/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 19:39:22 +0000</pubDate>
		<dc:creator>Adi</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[if]]></category>
		<category><![CDATA[quick]]></category>

		<guid isPermaLink="false">http://www.open-source-web.com/?p=74</guid>
		<description><![CDATA[This is a good alternative to using a basic IF condition. It basically fits the whole thing on a minimal line of code. It is an  easy way to compare two values and select the right one. There are a few ways to use this but the basic jist of it is to compare two [...]]]></description>
			<content:encoded><![CDATA[<p>This is a good alternative to using a basic IF condition. It basically fits the whole thing on a minimal line of code.</p>
<p>It is an  easy way to compare two values and select the right one. There are a few ways to use this but the basic jist of it is to compare two values and if its is true use the first value after the question mark, or if the condition returns false use the second value.</p>
<pre name="code" class="php">
echo $targetvar =  ($somevar == "thisVar" ? "itIsTrue" : "itIsFalse");
</pre>
<p><span style="font-size: 9pt; font-family: 'Arial','sans-serif';"><br />
In the example above we can set $targetvar with the condition. it will compare the first two variables with whatever you use, more then less then etc and it will choose the correct value from the two after the question mark.<br />
</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.open-source-web.com/php/shorthand-boolean-if-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SEO Friendly Redirects with PHP</title>
		<link>http://www.open-source-web.com/php/seo-friendly-redirects-with-php/</link>
		<comments>http://www.open-source-web.com/php/seo-friendly-redirects-with-php/#comments</comments>
		<pubDate>Sat, 24 Jan 2009 19:32:15 +0000</pubDate>
		<dc:creator>Adi</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[redirect]]></category>

		<guid isPermaLink="false">http://www.open-source-web.com/?p=60</guid>
		<description><![CDATA[With a basic redesign you probably wont have this problem but if you have rebuilt a website even with the same content if the URL&#8217;s have changed this will have a huge effect on your search engine presence as you will be starting from scratch. Your links from internal pages may not work, links from [...]]]></description>
			<content:encoded><![CDATA[<p>With a basic redesign you probably wont have this problem but if you have rebuilt a website even with the same content if the URL&#8217;s have changed this will have a huge effect on your search engine presence as you will be starting from scratch. Your links from internal pages may not work, links from external sites wont work and you will lose your pagerank (if it ever mattered anyway.)</p>
<p>A good way to keep your sites listing after a redevelopment is to use a redirect. If you are using an Apache server you can use the .htaccess file to redirect.</p>
<p><code>Redirect 301 /oldpage.html /newpage.html</code></p>
<p>But some times this isnt the best way if you have to redirect hundreds of pages. The alternative is to use a header redirect in PHP. Most web based languages such as ASP or RUBY will do the same thing but with different code.</p>
<p><code><span class="html"><br />
<span class="default">&lt;?php</span></span></code></p>
<p><code><span class="html"><span class="comment">// make this code the first line<br />
</span><span class="default">header</span><span class="keyword">(</span><span class="string">"Location: /newpage.php"</span><span class="keyword">,</span><span class="default">TRUE</span><span class="keyword">,</span><span class="default">301</span><span class="keyword">);</span><span class="keyword"> </span></span></code><code><span class="html"><span class="default"> </span><span class="comment">// 301 Moved Permanently</span></span></code> to newpage.php<br />
<code><span class="html"><span class="keyword"> </span><span class="default">?&gt;</span></span></code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.open-source-web.com/php/seo-friendly-redirects-with-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Tracking visitors with PHP and Predefined variables</title>
		<link>http://www.open-source-web.com/php/tracking-visitors-with-php-and-predefined-variables/</link>
		<comments>http://www.open-source-web.com/php/tracking-visitors-with-php-and-predefined-variables/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 22:37:21 +0000</pubDate>
		<dc:creator>Adi</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[analytics]]></category>
		<category><![CDATA[predefined]]></category>
		<category><![CDATA[tracking]]></category>

		<guid isPermaLink="false">http://www.open-source-web.com/?p=29</guid>
		<description><![CDATA[Although Google analytics can tell us a lot about who is visiting our websites it is still flawed in many ways. Google analytics is a powerful tool but if the user has disabled Javascript or you want to know live stats it can be pretty useless. Developing our own can be much more versatile as [...]]]></description>
			<content:encoded><![CDATA[<p>Although Google analytics can tell us a lot about who is visiting our websites it is still flawed in many ways. Google analytics is a powerful tool but if the user has disabled Javascript or you want to know live stats it can be pretty useless.</p>
<p>Developing our own can be much more versatile as we can gather information straight from the server using PHP&#8217;s Predefined variables.</p>
<p>You can add your own version of with a database and a few lines of PHP code.</p>
<pre class="php" name="code">
$time = mktime();
if (isset($_SERVER['REQUEST_METHOD'])) {   // HTTP-method
   $method = $_SERVER['REQUEST_METHOD'];
} else {
   $method = "";
}
if (isset($_SERVER['REMOTE_ADDR'])) {      // IP-adress
   $ip_adress = $_SERVER['REMOTE_ADDR'];
} else {
   $ip_adress = "";
}
if (isset($_SERVER['HTTP_USER_AGENT'])) {  // Browser
   $browser = $_SERVER['HTTP_USER_AGENT'];
} else {
   $browser = "";
}
if (isset($_SERVER['PHP_SELF'])) {         // Current page
   $page = $_SERVER['PHP_SELF'];
} else {
   $page = "";
}
if (isset($_SERVER['HTTP_REFERER'])) {    // Previous page
   $referer = $_SERVER['HTTP_REFERER'];
} else {
   $referer = "";
}

$sql="INSERT INTO user_log (time, method, page, referer, adress, browser) // Insert into database as new row
					VALUES('$time','$method','$page','$referer','$ip_adress','$browser')";
mysql_query($sql);</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.open-source-web.com/php/tracking-visitors-with-php-and-predefined-variables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP foreach loop through post request</title>
		<link>http://www.open-source-web.com/php/php-foreach-loop-through-post-request/</link>
		<comments>http://www.open-source-web.com/php/php-foreach-loop-through-post-request/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 21:48:49 +0000</pubDate>
		<dc:creator>Adi</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[foreach]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[request]]></category>

		<guid isPermaLink="false">http://www.open-source-web.com/?p=22</guid>
		<description><![CDATA[I use a variation of this code on most websites I have coded as it is versitile and full of uses when working with dynamic content. An example might be reusing the same mail() function for differant forms, you could loop through what is posted to it and print it out in the body of [...]]]></description>
			<content:encoded><![CDATA[<p>I use a variation of this code on most websites I have coded as it is versitile and full of uses when working with dynamic content.  An example might be reusing the same mail() function for differant forms, you could loop through what is posted to it and print it out in the body of the mail.</p>
<p>The foreach loop will process each of the requests set to the page. The $_REQUEST can be changed to just $_POST to check only posted form data or any other type of request.</p>
<p>The following loop contains a few examples of what you could do with the request once you have it.</p>
<pre name="code" class="php">
foreach ($_REQUEST as $key =&gt; $value)
{
$value = mysql_real_escape_string( $value );
$value = addslashes($value);
$value = strip_tags($value);
if($value != ""){$requestnumber ++;}
echo $key. ' - '.$value.'&lt;/br&gt;';
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.open-source-web.com/php/php-foreach-loop-through-post-request/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

