Writing better code, and advancing in PHP
<p>I've been writing PHP code for about four years now, however I feel as if I I am a terrible programmer. Looking at other code on github, it just seems as if I couldn't write what others are writing. </p>

<p>Here is some sample code I have wrote: </p>

<pre><code>&lt;?php

/* spotprice.php: Get lastest prices for Gold, Silver, Platinum, and Palladium */


/*
Spot prices for US commodities market only.
*/


$debug = 1;


$time = date("Hi");
$date = date("m/d/Y g:iA");


//Is the market open?
if ($time &lt;130 || $time &gt; 1605)
{
    echo "Market is currently closed";
    die();
}
else
{
    //Market is open! 
    $type = array("GOLD", "SILVER", "PLATINUM", "PALLADIUM");

    foreach ($type as $v){

        $price = file_get_contents('http://www.monex.com/data/prices.dat');
        preg_match_all('/^\s*.?"'.$v.'" (\d+)\.(\d+)\s*$/m', $price, $data);
        $lastPrice = $data[1][0].".".$data[2][0]; 
        $highPrice = $data[1][1].".".$data[2][1]; 
        $lowPrice = $data[1][2].".".$data[2][2]; 
        $currentPrice = $data[1][3].".".$data[2][3]; 
        $priceChange = number_format($currentPrice-$lastPrice, 2);

        //Debug
        if ($debug == "1"){
        print "&lt;br&gt;Current Price for $v: $currentPrice&lt;br&gt;";
        print "Change: $priceChange&lt;br&gt;";
        }


        //Insert prices into database
        $connect = mysql_connect("localhost","root","");
        mysql_select_db("dm", $connect);
        mysql_query("UPDATE spot_price SET lastPrice = '$lastPrice', highPrice = '$highPrice', lowPrice= '$lowPrice', currentPrice = '$currentPrice', priceChange = '$priceChange', updateTime = '$date' WHERE type = '$v'");
        mysql_close($connect);

    }
}
</code></pre>

<p>It does what I want it to do, but I feel like if I were to show another programmer this code, they would think I was some amateur. What can I do to better improve the above script? Or how would the same thing be written in the format below (ProductScraper.php)</p>

<p>This is what I want my code to look like: <a href="https://raw.github.com/ambertch/php-product-scraper/master/ProductScraper.php" rel="nofollow">https://raw.github.com/ambertch/php-product-scraper/master/ProductScraper.php</a></p>

<p>Now when I look at this, I see some advanced programmer. I never write classes and my code is always as written as above. How can I learn to advanced and step the next step to program something similar to ProductScraper.php?</p>

<p>I always tend to see</p>

<pre><code> * @param string $url  
 * 
 * return array
</code></pre>

<p>in everything I think is advanced, why is this always there?</p>
