<> = PHP = PHP is a popular general-purpose scripting language that is especially suited to web development. * http://www.php.net/ == Console hello world == {{{#!highlight sh php php_echo.php chmod 755 php_echo.php ./php_echo.php }}} {{{#!highlight php #!/usr/bin/php }}} == syslog == Generate a system log message {{{#!highlight php }}} == 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 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 }}} == count == Count all elements in an array, or something in an object {{{#!highlight php }}} == sprintf == Return a formatted string {{{#!highlight php }}} == str_replace == Replace all occurrences of the search string with the replacement string {{{#!highlight php $bodytag = str_replace("%body%", "black", ""); ?> }}} == Class == {{{#!highlight php 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; } } ?> }}} == Predefined variables == * $GLOBALS * $_SERVER * $_GET * $_POST * $_COOKIE * $_FILES * $_ENV * $_REQUEST * $_SESSION == foreach == {{{#!highlight php 10,'eleven'=>11,'twelve'=>12); foreach($listxassocx as $keyx=>$valx){ print("Itemx: $keyx: $valx "); } ?> }}} == explode == Split a string by string {{{#!highlight php }}} == preg_split == Split the given string by a regular expression {{{#!highlight php }}} == file_get_contents == Reads entire file into a string {{{#!highlight php }}} == DOMDocumentDOMDocument::loadXML == Load XML from a string {{{#!highlight php getElementsByTagName('loc'); ?> }}} == CORS (cross origin resource sharing) == === read.example.org/index.php === {{{#!highlight php }}} === auth.example.org/index.php === {{{#!highlight php }}} === app.example.org/index.html === {{{#!highlight html

}}} === vhosts === {{{ ServerName app.example.org DocumentRoot "/var/www/htdocs/app.example.org" Require local AllowOverride All ServerName auth.example.org DocumentRoot "/var/www/htdocs/auth.example.org" Require local AllowOverride All ServerName read.example.org DocumentRoot "/var/www/htdocs/read.example.org" Require local AllowOverride All }}} == Enable PHP in Slackware64 == {{{#!highlight sh # enable line /etc/httpd/httpd.conf sed -i 's/#Include \/etc\/httpd\/mod_php.conf/Include \/etc\/httpd\/mod_php.conf/g' httpd.conf #update mod_php.conf to point to the right path of libphp5.so LoadModule php5_module /usr/lib64/httpd/modules/libphp5.so SetHandler application/x-httpd-php #restart httpd/apache sh /etc/rc.d/rc.httpd restart }}} === /var/www/htdocs/teste.php === {{{#!highlight php }}} * http://localhost/teste.php === /var/www/htdocs/log.php === {{{#!highlight php }}} * http://localhost/log.php?msg=Test%20message%20!!! == Current date == {{{#!highlight php }}}