<?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>Krio Media &#187; PHP</title>
	<atom:link href="http://www.krio.me/category/development-info/learn-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.krio.me</link>
	<description></description>
	<lastBuildDate>Mon, 05 Jul 2010 06:27:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Loop twice through a PHP / MySQL result set</title>
		<link>http://www.krio.me/loop-twice-through-a-php-mysql-result-set/</link>
		<comments>http://www.krio.me/loop-twice-through-a-php-mysql-result-set/#comments</comments>
		<pubDate>Fri, 02 Jul 2010 22:39:29 +0000</pubDate>
		<dc:creator>Kevin Rio</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP Tutorials]]></category>

		<guid isPermaLink="false">http://www.krio.me/?p=1125</guid>
		<description><![CDATA[I get asked all the time if it is possible to loop multiple times through a MySQL result set in PHP. Here&#8217;s the answer. First, you&#8217;ll need a MySQL result set. To do that you&#8217;ll need to select something from your database and loop through it like so: $result = mysql_query(&#34;SELECT * FROM my_table&#34;); while($row [...]]]></description>
			<content:encoded><![CDATA[<p>I get asked all the time if it is possible to loop multiple times through a MySQL result set in PHP. Here&#8217;s the answer.</p>
<p><span id="more-1125"></span></p>
<p>First, you&#8217;ll need a MySQL result set. To do that you&#8217;ll need to select something from your database and loop through it like so:</p>
<pre class="brush: php;">

$result = mysql_query(&quot;SELECT * FROM my_table&quot;);

while($row = mysql_fetch_assoc($result)) {

// inside the loop

}
</pre>
<p>The problem is, if you want to loop through the same result set again, you will get an error because the internal pointer is currently at the end of the result. You will need to put the pointer back at the beginning of the result set so that you can loop through it again.</p>
<p>You can do it with a helpful php function named mysql_data_seek.</p>
<pre class="brush: php;">

mysql_data_seek($result, 0); // set the pointer of the result set back to the beginning.

while($row2 = mysql_fetch_assoc($result)) {

// inside the loop

}
</pre>
<p>This demonstrates how, as a PHP website developer, you can reset the pointer of a MySQL result set, which will allow you to iterate through the result set for a second time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krio.me/loop-twice-through-a-php-mysql-result-set/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ternary Operators in PHP: Shorthand If Else Statements</title>
		<link>http://www.krio.me/ternary-operators-in-php-shorthand-if-else-statements/</link>
		<comments>http://www.krio.me/ternary-operators-in-php-shorthand-if-else-statements/#comments</comments>
		<pubDate>Sat, 17 Apr 2010 19:08:09 +0000</pubDate>
		<dc:creator>Kevin Rio</dc:creator>
				<category><![CDATA[PHP Tutorials]]></category>

		<guid isPermaLink="false">http://www.krio.me/?p=1106</guid>
		<description><![CDATA[If-Else statements are a vital part of programming, however sometimes all the code that goes into writing are not required, especially if only only simple condition is needed. This is what the ternary operator is used for. The ternary operator is a shorthand if/else statement. It allows developers to form conditions quickly and in a [...]]]></description>
			<content:encoded><![CDATA[<p>If-Else statements are a vital part of programming, however sometimes all the code that goes into writing are not required, especially if only only simple condition is needed. This is what the ternary operator is used for.<span id="more-1106"></span></p>
<p>The ternary operator is a shorthand if/else statement. It allows developers to form conditions quickly and in a very readable fashion.</p>
<h3>Here is the ternary syntax</h3>
<pre class="brush: php;">

(condition) ? true-stuff-here : false-stuff-here;
</pre>
<p>Here is an example of the ternary operator</p>
<pre class="brush: php;">

$age = 20;

$response = ($age &gt; 29) ? 'He's in his thirties' : 'He's not';

echo $response; // He's not
</pre>
<p>I hope you can see the usefulness in the ability for the ternary operator to easily perform conditional comparisons. Please however, refrain from using &#8216;nested ternary comparisons&#8217; as the are very difficult to  so read. It is so frowned upon by web developers that I&#8217;m not even going to post an example.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krio.me/ternary-operators-in-php-shorthand-if-else-statements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sort an Array in PHP by Date</title>
		<link>http://www.krio.me/sort-an-array-in-php-by-date/</link>
		<comments>http://www.krio.me/sort-an-array-in-php-by-date/#comments</comments>
		<pubDate>Sat, 17 Apr 2010 18:45:41 +0000</pubDate>
		<dc:creator>Kevin Rio</dc:creator>
				<category><![CDATA[PHP Tutorials]]></category>

		<guid isPermaLink="false">http://www.krio.me/?p=1104</guid>
		<description><![CDATA[Sorting an array in PHP is not as difficult as many people make it out to be. This quick tutorial will walk you through the steps necessary to sort a date array. Sorting a PHP Array by Date The first step is ensuring that the dates are placed into the array in proper format. When [...]]]></description>
			<content:encoded><![CDATA[<p>Sorting an array in PHP is not as difficult as many people make it out to be. This quick tutorial will walk you through the steps necessary to sort a date array. <span id="more-1104"></span></p>
<h3>Sorting a PHP Array by Date</h3>
<p>The first step is ensuring that the dates are placed into the array in proper format. When you add the date to the array, the best and most compatible way to do do is to run the PHP date function on the date value. This function works no matter what format the date is in, including a MySQL datetime column or a PHP timestamp.</p>
<p>So to enter dates into your array you can do something like:</p>
<pre class="brush: php;">
$dateArray[] = date('Y-m-d');

//If you are iterating through something like a database with date's you could do something like:

$dateArray[] = date('Y-m-d', $row['date']);
</pre>
<h3>One you have your date array set</h3>
<p>All you need to do is run a  sorting function on the array.</p>
<h3>Most recent date first</h3>
<pre class="brush: php;">

rsort($dateArray);
</pre>
<h3>Oldest date first</h3>
<pre class="brush: php;">
sort($dateArray);
</pre>
<p>I hope this quick tutorial will help you in your website development and design endeavors!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krio.me/sort-an-array-in-php-by-date/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Craigslist Classifieds PHP Clone Script</title>
		<link>http://www.krio.me/craigslist-classifieds-php-clone-script/</link>
		<comments>http://www.krio.me/craigslist-classifieds-php-clone-script/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 15:59:12 +0000</pubDate>
		<dc:creator>Kevin Rio</dc:creator>
				<category><![CDATA[PHP Scripts]]></category>

		<guid isPermaLink="false">http://www.krio.me/?p=993</guid>
		<description><![CDATA[This is a bare-bones classifieds script that will help web developers to quickly build a full-featured Craigslist clone. About This Craigslist Clone This script is a framework that can be used to get your classifieds site up and running quickly. Classifieds Features Users can register / login / logout Users can post a classifieds ad Users can [...]]]></description>
			<content:encoded><![CDATA[<p>This is a bare-bones classifieds script that will help web developers to quickly build a full-featured Craigslist clone. <span id="more-993"></span></p>
<h3>About This Craigslist Clone</h3>
<p>This script is a framework that can be used to get your classifieds site up and running quickly.</p>
<h3>Classifieds Features</h3>
<ul>
<li>Users can register / login / logout</li>
<li>Users can post a classifieds ad</li>
<li>Users can post images</li>
<li>Admin&#8217;s can set categories in database</li>
<li>Admin&#8217;s can set locations in database</li>
<li>Admin&#8217;s can easily skin the script to fit within their already running sites / templates</li>
<li>This script is completely free for website developers to use in any of your personal or commercial scripts and websites.</li>
<li>The entire script is organized into an easy to understand filesystem with easily to use classes and methods.</li>
</ul>
<h3>What you can use this classifieds script for</h3>
<p>To best use this script, you are going to need to integrate it into your own website design. You should have some knowledge of HTML/CSS to do this. You don&#8217;t need any knowledge of PHP, just copy the the text between the php tags inside of your HTML.</p>
<h3>Usage</h3>
<ul>
<li>Install the classifieds.sql file into your database (via phpMyAdmin or something similar)</li>
<li>Open Db.php and input your database credentials</li>
<li>Open URLs.php and in put the location where you installed the classifieds script</li>
<li>Start skinning and using the script!</li>
</ul>
<p><a title="Classifieds Craigslist Clone Script" href="http://www.krio.me/files/classifieds.zip"><img title="Download File" src="http://www.krio.me/wp-content/themes/krio/img/downloadnow.png" alt="" width="185" height="62" /></a></p>
<p>Feel free to <a title="Contact Krio Media" href="http://www.krio.me/contact/">contact me</a> if you would like me to extend the features or customize this script for you on a contract basis. I&#8217;m a local Miami Website Designer and Developer that has worked on  an array of different types of web development projects.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krio.me/craigslist-classifieds-php-clone-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Check If A Number Is Between Two Values Tutorial</title>
		<link>http://www.krio.me/how-to-check-if-a-number-is-between-two-values-tutorial/</link>
		<comments>http://www.krio.me/how-to-check-if-a-number-is-between-two-values-tutorial/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 04:43:31 +0000</pubDate>
		<dc:creator>Kevin Rio</dc:creator>
				<category><![CDATA[PHP Tutorials]]></category>

		<guid isPermaLink="false">http://www.krio.me/?p=1051</guid>
		<description><![CDATA[This tutorial will show you how to build a function that will validate if a number falls between a specific range of values. To use this function, provide a maximum and a minimum number, along with the number that will be checked. Website developers can use this to validate ages etc&#8230; The function to check [...]]]></description>
			<content:encoded><![CDATA[<p>This tutorial will show you how to build a function that will validate if a number falls between a specific range of values. <span id="more-1051"></span>To use this function, provide a maximum and a minimum number, along with the number that will be checked. Website developers can use this to validate ages etc&#8230;</p>
<h3>The function to check if value is within a two number range</h3>
<pre class="brush: php;">
function numberBetween($numToCheck, $high, $low) {
if($numToCheck &lt;= $low) return false;
if($numToCheck &gt;= $high) return false;
return true;
}
</pre>
<h3>How to call the function</h3>
<pre class="brush: php;">

if (numberBetween(35, 100, 20)) {

echo 'The value is in the range!';

} else {

echo 'The value is outside the range!';

}
</pre>
<p>In this example, the value returned would be true because 35 is between 100 and 20.</p>
<p>I hope this data validation function will help you in your website development endeavors. It should simplify your development of a function that checks to see if a number (integer) falls between two values (range of numbers).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krio.me/how-to-check-if-a-number-is-between-two-values-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Validate A URL in PHP Tutorial</title>
		<link>http://www.krio.me/how-to-validate-a-url-php/</link>
		<comments>http://www.krio.me/how-to-validate-a-url-php/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 04:35:32 +0000</pubDate>
		<dc:creator>Kevin Rio</dc:creator>
				<category><![CDATA[PHP Tutorials]]></category>

		<guid isPermaLink="false">http://www.krio.me/?p=1035</guid>
		<description><![CDATA[This tutorial will teach you how to build a function that can be used by PHP developers to validate a URL data-type. All you need to do is pass in variable data to the function and it will return true if it is a proper URL or false if it is not. Use this to [...]]]></description>
			<content:encoded><![CDATA[<p>This tutorial will teach you how to build a function that can be used by PHP developers to validate a URL data-type.<br />
<span id="more-1035"></span><br />
All you need to do is pass in variable data to the function and it will return true if it is a proper URL or false if it is not. Use this to easily check is a variable is a properly formed URL. It uses a regular expression (regex) to validate the URL.</p>
<h3>The URL Data Validation Function</h3>
<pre class="brush: php;">

function validateURL($URL) {
return (bool)preg_match(&quot;/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i&quot;, $URL);
}
</pre>
<h3>How To Call The Function</h3>
<pre class="brush: php;">

if (validateURL('http://www.krio.me') {

// If URL is valid, do something here

}
</pre>
<p>Use this in all of your PHP scripts to ensure that input provided by users for URL&#8217;s is of a valid data type. Need a website developer to help you out? <a title="Miami Website Designer" href="http://www.krio.me/contact/">Contact me</a> if you need some help. I&#8217;m a web developer and designer local to Miami, Florida.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krio.me/how-to-validate-a-url-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to add data to an XML file in PHP</title>
		<link>http://www.krio.me/how-to-add-data-to-an-xml-file-in-php/</link>
		<comments>http://www.krio.me/how-to-add-data-to-an-xml-file-in-php/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 15:55:52 +0000</pubDate>
		<dc:creator>Kevin Rio</dc:creator>
				<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.krio.me/?p=974</guid>
		<description><![CDATA[Manipulating XML files is not something all developers deal with on a daily basis, but it is something that must be done. This series of posts will each showcase the most popular XML manipulation techniques that a developer should know. In this entry you will learn how to add elements and text to an XML [...]]]></description>
			<content:encoded><![CDATA[<p>Manipulating XML files is not something all developers deal with on a daily basis, but it is something that must be done. This series of posts will each showcase the most popular XML manipulation techniques that a developer should know. In this entry you will learn how to add elements and text to an XML file from PHP.<span id="more-974"></span></p>
<h3>Our XML File</h3>
<p>Here is our XML file.</p>
<p>We are going to insert a new &lt;Link&gt; child element that holds sibling elements &lt;title&gt; and &lt;url&gt;.</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?&gt;
&lt;MyLinksCentral&gt;
    &lt;Links&gt;
        &lt;Link&gt;
            &lt;title&gt;Krio Media&lt;/title&gt;
            &lt;url&gt;http://www.krio.me&lt;/url&gt;
        &lt;/Link&gt;
        &lt;Link&gt;
            &lt;title&gt;SEO Miami&lt;/title&gt;
            &lt;url&gt;http://www.mercadeoporinternet.com/&lt;/url&gt;
        &lt;/Link&gt;
    &lt;/Links&gt;
&lt;/MyLinksCentral&gt;
</pre>
<h3>How To Add The XML Elements</h3>
<p>And here is how we add the new elemnts to the document</p>
<pre class="brush: xml;">
  $xdoc = new DomDocument;
  $xdoc-&gt;Load('MyLinksCentral.xml');

        $links = $xdoc-&gt;getElementsByTagName('Links')-&gt;item(0);
        $newLinkElement = $xdoc -&gt;createElement('Link');
        $newTitleElement = $xdoc -&gt;createElement('title');
        $newURLElement = $xdoc -&gt;createElement('url');

        $urlNode = $xdoc -&gt;createTextNode ('Google');
        $titleNode = $xdoc -&gt;createTextNode ('http://www.google.com');

        $newTitleElement -&gt; appendChild($titleNode);
        $newURLElement -&gt; appendChild($urlNode);

        $newLinkElement -&gt; appendChild($newTitleElement);
        $newLinkElement -&gt; appendChild($newURLElement);

        $links -&gt; appendChild($newLinkElement);

$xdoc-&gt;save('MyLinksCentral.xml');
</pre>
<h3>Step-By-Step Analysis Of The XML</h3>
<p>Load &#8211; We load the XML file.</p>
<p>getElementsByTagName &#8211; We get the Links element, which holds all of our links.</p>
<p>createElement &#8211; We create the elements that we will be inserting into our XML file and save them into a variable.</p>
<p>createTextNode &#8211; We place the values of the elements into variables. In this case it is the URL and Title we want. We we will inserting Google as the Title and http://google.com as the URL.</p>
<p>appendChild &#8211; We put the text we just created into the actual elements &lt;title&gt; and &lt;url&gt;.</p>
<p>appendChild &#8211; The next set of appendChild&#8217;s are to place the complete &lt;title&gt; and &lt;url&gt; tags inside of our &lt;Link&gt; element.</p>
<p>The final appendChild is to insert the final &lt;Link&gt; tag into the &lt;Links&gt; element of the XML file to be saved.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krio.me/how-to-add-data-to-an-xml-file-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Web Scraper</title>
		<link>http://www.krio.me/free-php-web-scraper/</link>
		<comments>http://www.krio.me/free-php-web-scraper/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 15:22:47 +0000</pubDate>
		<dc:creator>Kevin Rio</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP Scripts]]></category>
		<category><![CDATA[Portfolio]]></category>

		<guid isPermaLink="false">http://www.krio.me/?p=529</guid>
		<description><![CDATA[A useful web scraper that can be used in an array of different development situations, including gathering product specifications from E-Commerce sites that do not provide an API or gathering useful information related to SEO techniques. I had to develop a web scraper for a proof-of-concept application a few months ago in PHP and since [...]]]></description>
			<content:encoded><![CDATA[<p>A useful web scraper that can be used in an array of different development situations, including gathering product specifications from E-Commerce sites that do not provide an API or gathering useful information related to SEO techniques. <span id="more-529"></span></p>
<p>I had to develop a web scraper for a proof-of-concept application a few months ago in PHP and since have had a few questions on how to implement them. I decided to make a post and include the web scraper free of charge for other developers to download and utilize in their scripts.</p>
<h3>What This Scraper Does</h3>
<p>This scraper uses the cURL PHP library in combination with 10 of the most popular search engines to gather information. First, it takes a string as a query provided by the user and searches the internet for sites relevant to that search query. It then visits and scrapes these sites for whatever regular expression you provide to it and stores these results into an array that can be placed into a database, xml file, or anything similar.</p>
<p><a title="PHP Web Scraper" href="http://www.krio.me/files/webscraper.zip"><img class="alignnone" title="Download File" src="http://www.krio.me/wp-content/themes/krio/img/downloadnow.png" alt="" width="185" height="62" /><br />
</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.krio.me/free-php-web-scraper/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Why Does PHP Have A Bad Reputation?</title>
		<link>http://www.krio.me/why-does-php-have-a-bad-reputation/</link>
		<comments>http://www.krio.me/why-does-php-have-a-bad-reputation/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 20:19:42 +0000</pubDate>
		<dc:creator>Kevin Rio</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Tutorials]]></category>

		<guid isPermaLink="false">http://www.krio.me/?p=513</guid>
		<description><![CDATA[Among senior developers, PHP is often seen as a tool for non-complex applications and rapid programming environments that may never be launched. I&#8217;m going to discuss the reasons for this, and things PHP developers can do to change this perception. I wanted to write this article to give both my opinions and observations since I [...]]]></description>
			<content:encoded><![CDATA[<p>Among senior developers, PHP is often seen as a tool for non-complex applications and rapid programming environments that may never be launched. I&#8217;m going to discuss the reasons for this, and things PHP developers can do to change this perception.<span id="more-513"></span></p>
<p>I wanted to write this article to give both my opinions and observations since I started using PHP in the mainstream business world. Lots of people have a poor view of PHP and its usage for business applications and complicated development sites. I&#8217;m going to explain why individuals and other website developers have this misconception and ways that PHP developers can improve their coding so that these myths can be forgotten.</p>
<p>One of the main reasons PHP is seen in a poor light is due to programmer inexperience. PHP is the next logical step for a web designer after they learn CSS and HTML because the barrier to entry is so low. Servers and inexpensive and the majority of designers and developers can easy use PHP scripts on their servers without any type of installation or configuration. This means that a higher percentage of new programmers and developers are using PHP, thus they may be using poor coding standards and bad practices.</p>
<h3>Why So Loose?</h3>
<p>PHP is a loosely typed language, which means that developers must be very careful when evaluating and comparing variables, because of this reason, new programmers (and even experienced developers from other languages) will have a difficult time writing effective code that evaluates properly.</p>
<pre class="brush: php;">

$myNum1 = 1;

$myNum2 = '1';

if ($myNum1 == $myNum2) echo 'Hey, they're equal! Well not really because one is an integer and another a string, BUT WHO CARES!';

if ($myNum1 === $myNum2) echo 'Hey, they're NOT equal! And this time, I'm right!';
</pre>
<h3>Developer Coding Standards</h3>
<p>Best practices are often something that inexperienced developers don&#8217;t follow, mostly because they don&#8217;t know that they exist. The majority of PHP programmers will follow the Zend guidelines for best programming practices. If a company you go to work for does not follow the <a title="Zend Coding Standard Guidelines" href="http://framework.zend.com/manual/en/coding-standard.html">Zend coding standard guidelines</a>, they surely will know about them, and you will easily be able to transfers this knowledge to whatever they are using. Its not so much about choosing which standards are right, but more about weeding out the poor standards that virtually everyone agrees on.</p>
<h3>My List Of The Most Common Errors / Inefficiencies</h3>
<ul class="listIt">
<li>Placing database calls and code within presentation and logic code</li>
<li>Note reusing code (See my introductory tutorial on <a title="Object Oriented PHP Developer" href="http://www.krio.me/the-basics-of-oop-for-the-php-programmer/">developing in OOP with PHP</a>)</li>
<li>Not filtering user input</li>
<li>Copying internet tutorial code and not reviewing it</li>
<li>Not planning to scale or understanding how to</li>
<li>Using a framework without first understanding the raw language</li>
</ul>
<h3>What These Errors Cause</h3>
<ul class="listIt">
<li>Exploits, such as SQL injection and cross-site scripting</li>
<li>Cluttered code that slows down future development</li>
<li>Debugging difficulties</li>
</ul>
<h3>How To Improve The Misconceptions</h3>
<ul class="listIt">
<li>Learn about caching both database calls and your code</li>
<li>Figure out how to sanitize input</li>
<li>Learn programming fundamentals and standards</li>
<li>Make sure PHP is the right tool for the job</li>
</ul>
<p>New developers are often the reasons for PHP having such a bad reputation with big business. Experienced programmers can write excellent PHP code that is more efficient and effective than other popular web programming languages, however the ability for anyone to start writing PHP code has been both a blessing and a curse upon the language.</p>
<p>Developers will often read a framework&#8217;s site and see promises like &#8216;Improve your development time by 50%!&#8217;. Well, all seems great, except that inexperienced programmers will take this to heart before they even start writing real PHP code, which often-times leads to a bloated code-base.</p>
<h3>PHP Is Slow</h3>
<p>This is true. PHP is a language that will always need to utilize caching on all projects with high traffic, however this problem is not PHP specific. If your&#8217;re developing a high traffic PHP application, you need to research <a title="Memcached " href="http://memcached.org/">memcached</a>.</p>
<h3>Other Things To Remember When Developing PHP Code</h3>
<p>PHP was created as a web templating engine, it was not meant to be an all-encompassing language. You should understand this before beginning to develop with it. What framework should I use? I hear Smarty is great! What about Codeigniter? First off, if you really need to ask which is the BEST, you probably have no clue how to actually use these tools to your advantage and should really stick with PHP until you have a firm understanding of it. Second, most developers critize templating engines like Smarty, because PHP was initially created as a web templating engine, so you going to template the template? Well, thats another topic all-together.</p>
<p>If you&#8217;re getting into PHP, I hope that this article has helped you to gain some understanding of areas that you should place some time when learning to develop PHP scripts and applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krio.me/why-does-php-have-a-bad-reputation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Basics of OOP For The PHP Programmer</title>
		<link>http://www.krio.me/the-basics-of-oop-for-the-php-programmer/</link>
		<comments>http://www.krio.me/the-basics-of-oop-for-the-php-programmer/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 21:30:24 +0000</pubDate>
		<dc:creator>Kevin Rio</dc:creator>
				<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.krio.me/?p=466</guid>
		<description><![CDATA[A detailed introduction into object oriented programming for PHP developers looking to expand their skills. OOP in PHP is the next step for any developer wanting to improve their code.  Why is learning object oriented programming so hard? Learning object oriented programming is the next logical step for any web developer wanting to advance their [...]]]></description>
			<content:encoded><![CDATA[<p>A detailed introduction into object oriented programming for PHP developers looking to expand their skills. OOP in PHP is the next step for any developer wanting to improve their code. <span id="more-466"></span></p>
<h3>Why is learning object oriented programming so hard?</h3>
<p>Learning object oriented programming is the next logical step for any web developer wanting to advance their career. Many website developers put off this step either because they don&#8217;t see its relevance or because they find it confusing. The main reason I noticed when I first started out was lack of use. Because there are alternative ways of writing code, individuals would rather not use OOP and use the procedural alternative, and as most of us know, the only way to advance knowledge of programming is through actually programming. It wasn&#8217;t until I started to learn C# that I actually started to apply OOP to my PHP work, mostly because in C# you have to use OOP so I picked it up very quickly.</p>
<p>I&#8217;m going to go over the basics of object oriented programming with PHP and hopefully clear up some of the confusion by using examples that relate directly to what you are probably doing on a daily basis as a PHP programmer. Once you start picking up these skills, make sure to USE THEM on a daily basis and everyday implement something new related to OOP or you will definitely never really learn to be effective with it. If you are reading this, I&#8217;m going to assume you probably now what OOP is and have tried to learn it before.  I&#8217;m not going to go over what OOP is, just HOW to use it with real world examples in PHP.</p>
<h1>A Useful CSS Class</h1>
<p>This class will allow you to develop an application to create CSS dynamically depending on whatever input you give it.</p>
<pre class="brush: php;">
class DynamicCSS
{
    protected $lineOfCSS = array();

    public function addCSS($property, $value)
    {
        $this-&gt;lineOfCSS[] = array(&quot;property&quot; =&gt; $property, &quot;value&quot; =&gt; $value);
    }

    public function run()
    {
        foreach ($this-&gt;lineOfCSS as $array) {
            $this-&gt;outputCSS($array['property'], $array['value']);
        }
    }

    public function outputCSS($property, $value)
    {
        echo &quot;{$property}: {$value};&quot;;
    }
}

$css = new DynamicCSS();
$css-&gt;addCss(&quot;display&quot;, &quot;none&quot;);
$css-&gt;run();
</pre>
<p>This class has an array named lineOfCSS, that will hold each line of CSS that we give it. It has the addCSS method that will handle adding the line to the array. It also has the run method, which will iterate through the array and pass the line to the outputCSS method, which will output it to the screen.<br />
The $this keyword is used to signify the use of a variable related directly to the specific instance of an object from the class you are currently using. If you have multiple objects from the same class, they all have their own variables and do not influence one another.</p>
<h1>Interfaces</h1>
<p>Think of an interface as a blueprint of methods that your classes can use. It is a skeleton that you can build off of later. Think of an interface as a way to link classes that are similar. Interfaces ensure that a class always has a specific method and that you never get a method undefined error.</p>
<p>To use an interface, your class must implement it.</p>
<pre class="brush: php;">

interface dbConnections {

function update();

function select();

}

class Db implements dbConnections {

public function update()  {

// update code here

}

protected function select()  {

// select code here

}

}
</pre>
<p>The interface makes sure that the Db class has an update a select method.</p>
<p>This example brings us to our final example every developer should know.</p>
<p>The private, protected, and public keywords.</p>
<h3>Private Keyword</h3>
<p>If a variable or method is labeled private, it can only be called from the class that it is declared in.</p>
<h3>Protected Keyword</h3>
<p>Protected variables and methods can be called from the class they were declared in and any class that is extended from this class.</p>
<h3>Public Keyword</h3>
<p>Variables and methods labeled public can be called from anywhere in the script.</p>
<h3>Final Keyword</h3>
<p>The final keyword is used on methods to ensure that is cannot be changed or overwritten. The following code will throw and error.</p>
<pre class="brush: php;">
class Display
{
final public function image()
{
echo &quot;&lt;img src='img.jpg'/&gt;&quot;;
}
}
class DisplayAgain extends Display
{
public function img()
{
echo &quot;&lt;img src='img2.jpg'/&gt;&quot;;
}
}&gt;</pre>
<p>I hope this introduction to object oriented programming has cleared up any confusion that you may have had. I&#8217;m going to turn this into a series now that the foundation has been set that will integrate more OOP and PHP topics to improve your website development skills.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krio.me/the-basics-of-oop-for-the-php-programmer/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
