'php' Category

  • Zend Framework 2 Cache Proxy – Cache Based Key Dependency.

    July 5, 2014

    Long time no ZF2 post, but here is something interesting peace of code that can solve cache problems present in most of the projects. I am assuming that, the reader knows how to create custom cache Factory in ZF2. Step 1. Edit your existing cache factory. See Line 35. namespace Application\Factory; use Application\Factory\CacheProxy; // Or […]

  • How to create google login on my site with openid in 5 min

    August 21, 2013

    As always we go straight to coding. Download how-to-create-google-login-on-my-site-with-openid-in-5-min.zip

  • How to get an unique identifier for php closure ?

    June 17, 2013

    Right to the example… $identifier = spl_object_hash(function(){ // some function content }); Simple as that. Suggestions or problems ? Write a comment.

  • How to read csv file into array ?

    June 16, 2013

    function csvToArray($file){ $rows = array(); $headers = array(); if(file_exists($file) && is_readable($file)){ $handle = fopen($file, 'r'); while (!feof($handle) ) { $row = fgetcsv($handle, 10240); if(empty($headers)) $headers = $row; else if(is_array($row)) $rows[] = array_combine($headers, $row); } fclose($handle); } else { throw new Exception($file.' doesn`t exist or is not readable.'); } return $rows; } Simple as that. Suggestions […]

  • Zend Framework 2 ACL setup in 5 minutes – tutorial

    March 13, 2013

    In this tutorial you will learn how to setup zend framework 2 acl and check if user has access for current route. If you don`t have testing project , download one from here. Add file module.acl.roles in application/config/ Tip: In fact role resources may be zend framework 2 routes. return array( 'guest'=> array( 'home', 'login', […]

  • Zend Framework 2 hello world project

    March 13, 2013

    Download zend framework 2 hello word project.

  • How to convert european(eu) odds to united kingdom(uk) odds ?

    March 12, 2013

    A bit hard this one , but there is a way to convert EU odds to UK odds in php. function eu_to_uk_odds($odds){ if(floor($odds) !== $odds){ $odds = (string) round($odds – 1,2); $oddsArr = explode('.',$odds); $f1 = (int) $oddsArr[0].''.$oddsArr[1]; $f2 = str_pad('1', ($f1 >= 10 ? 3 : strlen($f1) ),'0',STR_PAD_RIGHT); $minDel = $this->gcd($f1,$f2); $odds = $f1 […]

  • How to count days between 2 dates in php

    March 11, 2013

    A simple solution to count days between 2 dates is using DateTime method since php 5.3 function getDaysBetweenDates($from,$to,$addLastDay = false){ $d1 = new \DateTime($from); $d2 = new \DateTime($to); if($addLastDay){ $d2->add(new \DateInterval('P1D')); } return $d1 -> diff($d2)->days; } echo getDaysBetweenDates('2013-03-01','2013-03-11'); //10 echo getDaysBetweenDates('2013-03-01','2013-03-11',true); //11 If you need to count the last day too , just pass […]

  • php how to calculate system processor/s load in percent

    February 7, 2013

    This simple function will allow us to control php performance at level we need. /** * Calculates the processor load in % * @see sys_getloadavg * @author Ivan Gospodinow * @site ivangospodinow.com * @date 07.02.2013 * @param int $coreCount * @param int $interval * @return float */ function systemLoadInPercent($coreCount = 2,$interval = 1){ $rs = […]

  • Comparing two objects in php

    January 24, 2013

    $areSame = (serialize($ob1) === serialize($ob2)); This easy way of comparing two objects in php.It will take in account object variables. Example : class ob1{ public $number = 1; } class ob2{ public $number = 1; } $areSame = serialize(new ob1()) === serialize(new ob2()) //$areSame = true; class ob1{ public $number = 1; } class ob2{ […]


Warning: Use of undefined constant XML - assumed 'XML' (this will throw an Error in a future version of PHP) in /home/c2kblate/sites/ivangospodinow.com/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1048
 
Powered by Wordpress and MySQL. Theme by Shlomi Noach, openark.org