PHP Basics and Demo HackU
Upcoming SlideShare
Loading in...5
×
 

PHP Basics and Demo HackU

on

  • 436 views

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

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

Statistics

Views

Total Views
436
Views on SlideShare
436
Embed Views
0

Actions

Likes
0
Downloads
9
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • 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 PHP Basics and Demo HackU Presentation Transcript

  • Glory with PHP Anshu Prateek
  • PHPHyperTextProcessor
  • 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 $
  • Helooo world!• <?php • php -r $greet =• $greet = “hello”; "hello";echo "$greet• Echo $greet.‟world‟; world";
  • 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…
  • 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 "]);
  • Arrays..• http://www.php.net/manual/en/function.array.ph p
  • 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); ?>
  • 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;
  • Fetching data from the web..• BOSS• Uses OAUTH
  • 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