To improve speed of your website it is a good practice to use PHP gzip. To use gzip in your web page include following snippet in your PHP file. This way you can easily include gzip compression on your web page. //put this on very top of you page if(extension_loaded(’zlib’)) { ob_start(’ob_gzhandler’); $compressed = ”; [...]
In: PHP
26 Jul 2010Sometimes, you just have to know what was the previous date. So, in order to use PHP to tell you what was date yesterday, use following snippet: 1 2 3 4 5 function date_yesterday() { return date(’d.m.Y’, strtotime( ‘-1 days’ )); } echo ‘Yesterday was: ‘ . date_yesterday();
In: PHP
23 Jul 2010To create RSS feed on one of my clients website, I used PHP generate RSS script. I hope it will be useful for all of PHP developers who want to create RSS feed on custom developed website. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 [...]
In: PHP
23 Jul 2010In order to prevent page to render in Zend Framework use following snippet. Zend no render: 1 $this->getHelper(’viewRenderer’)->setNoRender(); In order to disable layout use both lines as shown in snippet below: 1 2 $this->getHelper(’viewRenderer’)->setNoRender(); $this->_helper->layout->disableLayout();
In this snippet we shall see what is the way of using CSS file with no cache. In order to achieve this, we could include different CSS file every time. We won’t actually include different CSS file, but we shall send new param. This way, we will trick browser into thinking that there is a [...]
In: PHP
19 Jul 2010In order to use PHP to format number output, you should call for a number_format() PHP function using following params: float $number, int $decimals, string $decimalPoint, string $thousandsSeparator. Use this snippet in order to format number from example: 1 2 3 4 5 $number = 3221.22346; echo number_format($number, 2, ‘,’, ‘ ‘); // PHP [...]
In: PHP
15 Jul 2010Very often we have a need to calculate the time passed between two dates. In order to make it easy, here is a snippet in PHP that can calculate days between dates. PHP calculate days between dates snippet: 1 2 3 4 5 6 7 8 9 10 function calculate_days_between_dates($startDate, $endDate = null) { if(empty($endDate)) [...]
In: PHP
15 Jul 2010My friend asked me couple a days ago, how to make a sort of calculator for his client. Client should be able to type full formula to input field (something like “(3*2/6+4)*1.1″), and his website should output the data. So I came up with a simple PHP calculate function in order to make it easy [...]
PHP function fputs() writes string into an open file. The fputs function will stop at the end of the file or when it reaches the specified length, whichever comes first. PHP fputs function is an alias of the fwrite() function, so you can use either. 1 2 3 $file = fopen("fputs.txt", "w"); fputs($file, "PHP fputs [...]
In: PHP
14 Jul 2010In order to check size of a file, use PHP filesize function as shown in following snippet. This funtion will return you a file size in easy-to-read format. 1 2 3 4 5 6 7 8 9 function get_file_size($file) { $size = filesize($file); $units = array("B","kB","MB","GB","TB","PB","EB","ZB","YB"); foreach($units as $pow => $unit) { if($size / [...]