PHP Basics and Demo HackU

566 views

Published on

PHP Web primer slide for hackU at IIT Madras, 2012,

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
566
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
11
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • 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
  • PHP Basics and Demo HackU

    1. 1. Glory with PHP Anshu Prateek
    2. 2. PHPHyperTextProcessor
    3. 3. 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
    4. 4. What is it..?!• What is PHP?!• RasmusLerdorf – 1995• Compile or interpret?• CLI?
    5. 5. Pre-requisites LAMP/WAMP/MAMPL/W/M – Linux/Windows/Mac A – Apache M – Mysql P - PHP
    6. 6. 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!
    7. 7. 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 $
    8. 8. Helooo world!• <?php • php -r $greet =• $greet = “hello”; "hello";echo "$greet• Echo $greet.‟world‟; world";
    9. 9. Ways to put long text• <?php• $variable = „the long long long copied wikipedia text”; ?><html>…<body><?phpecho $text;?></body>
    10. 10. 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;
    11. 11. 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…
    12. 12. Arrays• $array = array( "foo" => "bar", 42 => 24, "multi" => array( "dimensional" => array( "array" => "foo" ) ) );• var_dump($array["foo"]); var_dump($array[42]); var_dump($array["multi"]["dimensional"]["array "]);
    13. 13. Arrays..• http://www.php.net/manual/en/function.array.ph p
    14. 14. Functions• Function <?php function renderList($array){ if( sizeof($array) > 0 ){ echo <ul>; foreach( $array as $key => $item ){ echo <li> . $key . : . $item . </li>; } echo </ul>; } } $lampstack = array( Operating System => Linux, Server => Apache, Database => MySQL, Language => PHP ); renderList($lampstack); ?>
    15. 15. Talking with your page• $_GET• Example.com/?query=hacku• $query = $_GET[„query‟]• $_POST• <form id=“iitm>• <input type=“text” name=“userid” />• <submit>• </form>$id = $_POST[„userid‟];$_COOKIES;
    16. 16. Fetching data from the web..• BOSS• Uses OAUTH
    17. 17. Adding it all up together..Pictionary!1)Getting the user provided text.2) Remove the blacklist words.3) Get image for the rest of the words.Show me the code..!https://github.com/anshprat/hacku

    ×