PHP cheatsheet

XML

When using DOMDocument, add a meta tag to make sure your HTML file is treated as 'UTF-8' encoded, this will cause a 'misplaced tag' warning, suppress with '@'

$doc = new DOMDocument();
@$doc->loadHTML('<meta http-equiv="content-type" content="text/html; charset=utf-8">' . $html);

mod_php vs. FastCGI vs. PHP-FPM

ref: http://www.openlogic.com/wazi/bid/209956/mod_php-vs-FastCGI-vs-PHP-FPM-for-Web-Server-Scripting

install php-fpm

ref: http://www.binarytides.com/install-nginx-php-fpm-mariadb-debian/

$ sudo apt-get install php5-fpm

# config files are at /etc/php5/fpm/

# restart php fpm
$ sudo service php5-fpm restart

php arrays

array elements order:

$a = array(1=>'1', 0=>0, 2=>2);

foreach ($a as $value) {
    echo $value . ' ';
}

output:

1 0 2

php resources

sites:

php coding styles