Home   -   Computerkurs   DemoMatrix   Editpointstatic   Folderwatcher   Gipsydrive   Licenses   Shrinkseries   V4   More...  

All   Asm   Bas   C   C++   C#   CSS   HTML   Java   JS   Lisp   OPAL   PHP   Perl   PS   Py   Rb   SQL   Win  

More  

Previous page Home chapter Next page

Trilo - Downtown - Languages

PHP

PHP is a scripting language targeted on website creation, usually running as a webserver component. PHP has full access to the local ressources (as opposed to JavaScript), it can e.g. write files to disk and execute local programs.

Arrays

PHP arrays are especially flexible. They can be indexed or associative, and they can be nested.

One german tutorial about using PHP arrays is www.php-einfach.de/php-tutorial/php-array.php/ (20120814°1012).   Tutorial
The official manual page about arrays http://php.net/manual/en/language.types.array.php (20120814°1011).   Manual

Strings

Determine how far two strings are identical

Problem: We have two strings and want know, up to which position they are identical.

A cool solution is found on Stackoverflow in tread "Find first character that is different between two strings", in the posting by ircmaxell on 2011-September-19. He says: "... when you xor two strings, the characters that are the same will become null bytes (chr(0)) ...". (20110923°0722).   BTW ircmaxell writes nice PHP articles in his blog blog.ircmaxell.com (20110923°0722).   Thread

E.g. in editpointstatic/esp.index.php in function 20110923°0721 it looks like this:

   $s1 = $_SERVER['HTTP_REFERER']; // "http://localhost/eps/testpage.html";
   $s2 = $_SERVER['SCRIPT_URI']    // "http://localhost/eps/eps/index.php";
   $sXor = $s1 ^ $s2;
   $iPos = strspn($sXor, chr(0));
   $sTail1 = substr($s1, $iPos);   // = "testpage.html"
   $sTail2 = substr($s2, $iPos);   // = "eps/index.php"

Networking

Send HTTP request

There are several ways to send a HTTP request, depending on the actual needs. Following are some examples (see also Stackoverflow link below). More sophisticated flavours are possible, e.g. for using a proxy or setting authentication.

   // just get the file content
   $xml = file_get_contents("http://www.example.com/file.xml");
   // have detailed control about the request and
   // have the ability to view the http response header
   $response = http_get("http://www.example.com/file.xml");
   // use the curl library
   $ch = curl_init("REMOTE XML FILE");
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($ch, CURLOPT_HEADER, 0);
   $data = curl_exec($ch);
   curl_close($ch);

Stackoverflow thread   How to send a GET request from PHP?   is enumerating some methods to do the job (20111212°2121). Thread

Classes

Since version 5, PHP is fully object oriented. More precisely: you can use classes, but need not.

The official manual page about object oriented programming in PHP: http://php.net/manual/en/language.oop5.php   (20120814°1301). Manual

Books

Jörg Krause: Kochbuch PHP5, (c) 2005 Carl Hanser Verlag München Wien, ISBN 3-446-22736-9, 508 pages, www.hanser.de/computer (20101220°2021). Some interesting demo files from this book are:

.

.

Products

PhpStorm, a PHP/JavaScript/CSS IDE, www.jetbrains.com/phpstorm, Personal License 89.00 EUR + VAT, 30 days evaluation version. (ws 20130430°203705)

.

Imprint : www.trilo.de