= PHP = http://www.php.net/ = syslog = Generate a system log message {{{#!highlight php <?php // levels LOG_EMERG LOG_ALERT LOG_CRIT LOG_ERR LOG_WARNING LOG_NOTICE LOG_INFO LOG_DEBUG syslog(LOG_INFO,'Hello here'); // In Slackware by default logs the message to /var/log/messages ?> }}} === Log levels and files in operative systems === ||'''OS''' || '''File'''|| '''Logged levels'''|| ||Slack64 14|| /var/log/messages|| INFO|| ||Slack64 14|| /var/log/syslog|| WARNING ERR CRIT|| ||CentOS 6.4|| /var/log/messages|| INFO WARNING ERR CRIT|| ||Ubuntu 12.04 Precise|| /var/log/syslog|| DEBUG INFO WARNING ERR CRIT|| ||Debian 7.0 Wheezy|| /var/log/syslog ||DEBUG INFO WARNING ERR CRIT|| == array == Create an array {{{!highlight php <?php $fruits = array ( "fruits" => array("a" => "orange", "b" => "banana", "c" => "apple"), "numbers" => array(1, 2, 3, 4, 5, 6), "holes" => array("first", 5 => "second", "third") ); $foo = array('bar' => 'baz'); echo "Hello {$foo['bar']}!"; // Hello baz! ?> }}} == array_push == Push one or more elements onto the end of array {{{#!highlight php <?php $array[] = $var; // push $var into $array $stack = array("orange", "banana"); array_push($stack, "apple", "raspberry"); ?> }}} == count == Count all elements in an array, or something in an object {{{#!highlight php <?php $a[0] = 1; $a[1] = 3; $a[2] = 5; $result = count($a); // $result == 3 }}} == intval == Get the integer value of a variable {{{#!highlight php <?php echo intval(42); // 42 echo intval(4.2); // 4 echo intval('42'); // 42 ?> }}} = sprintf = Return a formatted string {{{#!highlight php <?php echo sprintf('There are %d monkeys in the %s', 5, 'tree'); ?> }}} = str_replace = Replace all occurrences of the search string with the replacement string {{{#!highlight php <?php // Returns <body text='black'> $bodytag = str_replace("%body%", "black", "<body text='%body%'>"); ?> }}} == Class == {{{#!highlight php <?php class SimpleClass { // property declaration public $var = 'a default value'; // method declaration public function displayVar() { echo $this->var; } } class Foo { public static $my_static = 'foo'; public function staticValue() { return self::$my_static; } } class Bar extends Foo { public function fooStatic() { return parent::$my_static; } } class Foo { public static function aStaticMethod() { // ... } } class MyClass { const CONSTANT = 'constant value'; function showConstant() { echo self::CONSTANT . "\n"; } } class MyClass { public $public = 'Public'; protected $protected = 'Protected'; private $private = 'Private'; function printHello() { echo $this->public; echo $this->protected; echo $this->private; } } ?> }}}