Category Archives: PHP

PHP: How To Get A Time Difference in Human Readable Format

A simple function to return the time since a given timestamp in the past. function time_since($timestamp) { // Init $hash = array(); $now = time(); // Breakdown the time diff $diff = $now – $timestamp; $hash['day'] = floor($diff / 86400); … Continue reading

Posted in PHP | Tagged , , , | 1 Comment

PHP: Pass By Reference vs. Pass By Value

By default, PHP is pass by value. <? function pass_by_value($param) { push_array($param, 4, 5); } $ar = array(1,2,3); pass_by_value($ar); foreach ($ar as $elem) { print "<br>$elem"; } ?> The code above prints 1, 2, 3. This is because the array … Continue reading

Posted in PHP | Leave a comment

Perl Version of PHP's "ucwords" Function

my $string = ‘this is a string of text’; $string =~ s/\b(\w+)\b/ucfirst($1)/ge; print “$string\n”;

Posted in PHP, Perl | Leave a comment

How To Merge PHP Objects

foreach($objectA as $k => $v) $objectB->$k = $v;

Posted in PHP | Leave a comment

Minimal PhpMyAdmin new server config

Besides the boilerplate at the top, here’s the least you need to add another database server to the dropdown list in PhpMyAdmin: $i++; $cfg['Servers'][$i]['auth_type'] = ‘cookie’; $cfg['Servers'][$i]['host'] = ‘my.host.com’;

Posted in Linux, PhpMyAdmin | Leave a comment

How to Write to STDERR in PHP

Writing to standard error in PHP:    fwrite(STDERR, “hello error string\n”);  Useful for standalone PHP scripts.

Posted in PHP | Leave a comment