What is PHP?!PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.Code is interpreted by a Web server with a PHP processor module which generates the resulting Web page.Includes a command-line interface capability and can be used in standalone graphical applications
Agenda• The basics• Enough PHP to handle simple request• How to talk to backend data store using PHP• How to parse/generate XML/JSON in PHP
What is it..?!• What is PHP?!• RasmusLerdorf – 1995• Compile or interpret?• CLI?
Pre-requisites LAMP/WAMP/MAMPL/W/M – Linux/Windows/Mac A – Apache M – Mysql P - PHP
About me.. Err.. PHP Latest Version : 5.4.0 (released on march 01, 2012)Presently hosted on github: https://github.com/php/php-src Written in C, you can write your own modules!
The basics• Starts with <?php• <? Also accepted but recommended not to use due to xml usage• Closing ?> is not mandatory unless code structure requires closure.• Infact if possible, do not use closing ?> , helps avoid “header already sent” errors.• Double quotes allow variable substitution, single quotes don‟t.• Variables start with $
Ways to put long text• <?php• $variable = „the long long long copied wikipedia text”; ?><html>…<body><?phpecho $text;?></body>
Or use HEREDOC• <?php• $name = „doctor who‟;• $html=<<<HTML• this is some html• And some more html• And only html!• And I can use $name „s alien powers as well!• HTML;• echo $html;
Strings• http://us2.php.net/manual/en/ref.strings.php• The various inputs and outputs need to be formatted. Various functions.string substr ( string $string , int $start [, int $length ] )• string strstr ( string $haystack , mixed $needle [, bool $before_needle = false ] )• And many more…