Category Archives: PHP

PHP

PHP developers should try Python.

PHP and Python both are dynamic typed language, so there is no point the discuss anything related in this aspect. Exception is first class citizen try: a = 1 / 0 except: print ‘Caught’ Prints ‘Caught’ Let’s look at PHP: try{ $a = 1 / 0; }catch (Exception $e){ print “Caught”; } I cannot believe… Read More »

PHP Snippet: Get dates from a given range

function get_range_dates($start, $end){ $days = array(); $start_tmp = explode(“-“,$start); $end_tmp = explode(“-“,$end); $start_time = mktime(1,1,1, $start_tmp[1], $start_tmp[2], $start_tmp[0]); $end_time = mktime(1,1,1, $end_tmp[1], $end_tmp[2], $end_tmp[0]); while($start_time <= $end_time){ $days[] = date(“Y-m-d”, $start_time); $start_time += 86400; } return $days; } //calling the function get_range_dates(‘2011-02-01’, ‘2011-03-08’); Result: Array ( [0] => 2011-02-01 [1] => 2011-02-02 [2] => 2011-02-03… Read More »

Category: PHP

PHP Tutorial: Server load bar chart

Server Load: Just a quick tutorial on drawing the server load bar chart in php: serverload.php function get_server_load($windows = 0) { $os = strtolower(PHP_OS); if (strpos($os, “win”) === false) { if (file_exists(“/proc/loadavg”)) { $load = file_get_contents(“/proc/loadavg”); $load = explode(‘ ‘, $load); return $load; } elseif (function_exists(“shell_exec”)) { $load = explode(‘ ‘, `uptime`); return $load; }… Read More »

Category: PHP

My dokuwiki plugins

A while ago I wrote some dokuwiki plugins: User Home Page Auto Include Index Table Math Modal Popup ACL Made Easy

Category: PHP

How do you rotate a two dimensional array?

http://stackoverflow.com/questions/42519/how-do-you-rotate-a-two-dimensional-array This is the best so far I have come up with PHP, can anyone refine this for me?? $b = array(); $a = array(array(1,2,3,4),array(5,6,7,8),array(9,0,1,2),array(3,4,5,6)); while(count($a)>0) { $b[count($a[0])-1][] = array_shift($a[0]); if (count($a[0])==0) { array_shift($a); } }

Category: PHP