SlideShare a Scribd company logo
PHP for hacks
                 Tom Praison
    tpraison@yahoo-inc.com
       IIT-Delhi 16-Aug-2012
Sample Codes
• The sample code is available for download
  https://github.com/tompraison/php_sample
What we need to learn?
•   Enough PHP to handle simple request
•   How to talk to backend data store using PHP
•   How to parse XML/JSON in PHP
•   How to generate JSON in PHP
What is PHP?
• Server side language
• Very easy to learn
• Available on LAMP stack (Linux Apache Mysql
  PHP)
• Does not require any special tools. Create a file
  with .php extension and your done.
How it works?
Getting Started
•   You need a local server with PHP enabled.
•   XAMPP for windows
•   MAMP for Mac OSx
•   Linux has it by default
Getting Started



Create a file hello.php into htdocs and call it like this
http://localhost:8888/hello.php
           <?php
            $school="iit-delhi";
            echo "Hello, World $school";
           ?>
Basic Syntax
• PHP blocks start with <?php and end with ?> -
• Every line of PHP has to end with a semicolon
  ";”
• Variables in PHP start with a $
• You print out content to the document in PHP
  with the echo command.
• $school is variable and it can be printed out
• You can jump in and out of PHP anywhere in the
  document. So if you intersperse PHP with HTML
  blocks, that is totally fine. For example:
Mix Match
• You can mix and match HTML and PHP
        <?php
         $origin = 'Outer Space';
         $planet = 'Earth';
         $plan = 9;
         $sceneryType = "awful";
        ?>
        <h1>Synopsis</h1><p>It was a peaceful time on
        planet <?php echo $planet;?> and people in the
        <?php echo $sceneryType;?> scenery were
        unaware of the diabolic plan <?php echo
        $plan;?> from <?php echo $origin;?> that will
        take their senses to the edge of what can be
        endured.</p>



                                                         demo1.php
Displaying more complex data
• You can define arrays in PHP using the array()
  method
   $lampstack = array('Linux','Apache','MySQL','PHP');
• If you simply want to display a complex
  datatype like this in PHP for debugging you can
  use the print_r() command
  $lampstack = array('Linux','Apache','MySQL','PHP');
  print_r($lampstack);




                                                        demo2.php
Arrays
• Accessing arrays using index

    <ul>
    <?php
    $lampstack = array('Linux','Apache','MySQL','PHP');
    echo '<li>Operating System:'.$lampstack[0] . '</li>';
    echo '<li>Server:' . $lampstack[1] . '</li>';
    echo '<li>Database:' . $lampstack[2] . '</li>';
    echo '<li>Language:' . $lampstack[3] . '</li>';
    ?>
    </ul>




                                                            demo3.php
Arrays
• Iterating through arrays

    <ul>
    <?php
    $lampstack = array('Linux','Apache','MySQL','PHP');
    $labels = array('Operating System','Server','Database','Language');
    $length = sizeof($lampstack);
    for( $i = 0;$i < $length;$i++ ){
      echo '<li>' . $labels[$i] . ':' . $lampstack[$i] . '</li>';
    }
    ?>
    </ul>
          sizeof($array) - this will return the size of the array




                                                                    demo4.php
Associative Arrays
• PHP has associative arrays with string keys
<ul>
<?php
$lampstack = array(
  'Operating System' => 'Linux',
  'Server' => 'Apache',
  'Database' => 'MySQL',
  'Language' => 'PHP'
);
$length = sizeof($lampstack);
$keys = array_keys($lampstack);
for( $i = 0;$i < $length;$i++ ){
  echo '<li>' . $keys[$i] . ':' . $lampstack[$keys[$i]] . '</li>';
}
?>
</ul>


                                                                     demo5.php
Functions
<?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);
?>                                                  demo6.php
Interacting with the web - URL
                        parameters
<?php
$name = 'Tom';

// if there is no language defined, switch to English
if( !isset($_GET['language']) ){
  $welcome = 'Oh, hello there, ';
}
if( $_GET['language'] == 'hindi' ){
  $welcome = 'Namastae, ';
}
switch($_GET['font']){
  case 'small':
    $size = 80;
  break;
  case 'medium':
    $size = 100;
  break;
  case 'large':
    $size = 120;
  break;
  default:
    $size = 100;
  break;
}
echo '<style>body{font-size:' . $size . '%;}</style>';
echo '<h1>'.$welcome.$name.'</h1>';
?>

                                                         demo7.php
Loading content from the web

<?php
 // define the URL to load
 $url = 'http://cricket.yahoo.com/player-profile/Sachin-
Tendulkar_2962';
 // start cURL
 $ch = curl_init();
 // tell cURL what the URL is
 curl_setopt($ch, CURLOPT_URL, $url);
 // tell cURL that you want the data back from that URL
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 // run cURL
 $output = curl_exec($ch);
 // end the cURL call (this also cleans up memory so it is
 // important)
 curl_close($ch);
 // display the output
 echo $output;
?>




                                                             demo8.php
Displaying XML content
• Demo – Showing Twitter trends given a place
    – Displaying XML Content
    – Displaying JSON




demo9.php
Connecting to MySQL
• Demo10.php from source code
• Simple example to fetch data from DB
Further Reference
             http://www.php.net/
         http://developer.yahoo.com
      http://isithackday.com/hackday-
        toolbox/phpforhacks/index.html
   http://www.slideshare.net/tompraison
https://github.com/tompraison/php_sample

Recommended

Phphacku iitd
Phphacku iitd
Sorabh Jain
 
Php mysql
Php mysql
Manish Jain
 
Using PHP
Using PHP
Mark Casias
 
Sa
Sa
sahul azzez m.i
 
Class 6 - PHP Web Programming
Class 6 - PHP Web Programming
Ahmed Swilam
 
Php hacku
Php hacku
Tom Praison Praison
 
HackU PHP and Node.js
HackU PHP and Node.js
souridatta
 
Php Lecture Notes
Php Lecture Notes
Santhiya Grace
 
07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards
Denis Ristic
 
PHP Workshop Notes
PHP Workshop Notes
Pamela Fox
 
Intro to php
Intro to php
Sp Singh
 
Data Types In PHP
Data Types In PHP
Mark Niebergall
 
Introduction to PHP
Introduction to PHP
Bradley Holt
 
PHP POWERPOINT SLIDES
PHP POWERPOINT SLIDES
Ismail Mukiibi
 
Intro to PHP
Intro to PHP
Sandy Smith
 
Introduction to PHP
Introduction to PHP
Jussi Pohjolainen
 
Loops PHP 04
Loops PHP 04
mohamedsaad24
 
Intermediate PHP
Intermediate PHP
Bradley Holt
 
PHP - Introduction to PHP
PHP - Introduction to PHP
Vibrant Technologies & Computers
 
PHP and MySQL
PHP and MySQL
webhostingguy
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
wahidullah mudaser
 
Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1
Gheyath M. Othman
 
Introduction to php web programming - get and post
Introduction to php web programming - get and post
baabtra.com - No. 1 supplier of quality freshers
 
Introduction to PHP
Introduction to PHP
Collaboration Technologies
 
What Is Php
What Is Php
AVC
 
Basics PHP
Basics PHP
Alokin Software Pvt Ltd
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
webhostingguy
 
Open Source Package PHP & MySQL
Open Source Package PHP & MySQL
kalaisai
 
Ideation101 - Hacku ideas
Ideation101 - Hacku ideas
Sorabh Jain
 
Advanced Php/Mysql Training With live project
Advanced Php/Mysql Training With live project
Shaheel Khan
 

More Related Content

What's hot (20)

07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards
Denis Ristic
 
PHP Workshop Notes
PHP Workshop Notes
Pamela Fox
 
Intro to php
Intro to php
Sp Singh
 
Data Types In PHP
Data Types In PHP
Mark Niebergall
 
Introduction to PHP
Introduction to PHP
Bradley Holt
 
PHP POWERPOINT SLIDES
PHP POWERPOINT SLIDES
Ismail Mukiibi
 
Intro to PHP
Intro to PHP
Sandy Smith
 
Introduction to PHP
Introduction to PHP
Jussi Pohjolainen
 
Loops PHP 04
Loops PHP 04
mohamedsaad24
 
Intermediate PHP
Intermediate PHP
Bradley Holt
 
PHP - Introduction to PHP
PHP - Introduction to PHP
Vibrant Technologies & Computers
 
PHP and MySQL
PHP and MySQL
webhostingguy
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
wahidullah mudaser
 
Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1
Gheyath M. Othman
 
Introduction to php web programming - get and post
Introduction to php web programming - get and post
baabtra.com - No. 1 supplier of quality freshers
 
Introduction to PHP
Introduction to PHP
Collaboration Technologies
 
What Is Php
What Is Php
AVC
 
Basics PHP
Basics PHP
Alokin Software Pvt Ltd
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
webhostingguy
 
Open Source Package PHP & MySQL
Open Source Package PHP & MySQL
kalaisai
 

Viewers also liked (9)

Ideation101 - Hacku ideas
Ideation101 - Hacku ideas
Sorabh Jain
 
Advanced Php/Mysql Training With live project
Advanced Php/Mysql Training With live project
Shaheel Khan
 
Java performance
Java performance
Sachin Shukla
 
21146103 김남희
21146103 김남희
kimnamhee
 
Hacking with Semantic Web
Hacking with Semantic Web
Tom Praison Praison
 
Planning LAMP infrastructure
Planning LAMP infrastructure
David Timothy Strauss
 
HackU: How to think of a great idea
HackU: How to think of a great idea
Tom Praison Praison
 
Backend accessible
Backend accessible
Mark Casias
 
Tool Up Your LAMP Stack
Tool Up Your LAMP Stack
Lorna Mitchell
 
Ideation101 - Hacku ideas
Ideation101 - Hacku ideas
Sorabh Jain
 
Advanced Php/Mysql Training With live project
Advanced Php/Mysql Training With live project
Shaheel Khan
 
21146103 김남희
21146103 김남희
kimnamhee
 
HackU: How to think of a great idea
HackU: How to think of a great idea
Tom Praison Praison
 
Backend accessible
Backend accessible
Mark Casias
 
Tool Up Your LAMP Stack
Tool Up Your LAMP Stack
Lorna Mitchell
 

Similar to PHP for hacks (20)

sumana_PHP_mysql_IIT_BOMBAY_2013
sumana_PHP_mysql_IIT_BOMBAY_2013
Sumana Hariharan
 
PHP Basics and Demo HackU
PHP Basics and Demo HackU
Anshu Prateek
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
Php introduction
Php introduction
Osama Ghandour Geris
 
PHP Programming: Intro
PHP Programming: Intro
Things Lab
 
Phpbasics
Phpbasics
PrinceGuru MS
 
PHP
PHP
sometech
 
05php
05php
anshkhurana01
 
Php classes in mumbai
Php classes in mumbai
Vibrant Technologies & Computers
 
MIND sweeping introduction to PHP
MIND sweeping introduction to PHP
BUDNET
 
rtwerewr
rtwerewr
esolinhighered
 
Quick beginner to Lower-Advanced guide/tutorial in PHP
Quick beginner to Lower-Advanced guide/tutorial in PHP
Sanju Sony Kurian
 
php 1
php 1
tumetr1
 
05php
05php
Shahid Usman
 
Day1
Day1
IRWAA LLC
 
PHP Hypertext Preprocessor
PHP Hypertext Preprocessor
adeel990
 
Php introduction with history of php
Php introduction with history of php
pooja bhandari
 
php fundamental
php fundamental
zalatarunk
 
php
php
Ramki Kv
 
sumana_PHP_mysql_IIT_BOMBAY_2013
sumana_PHP_mysql_IIT_BOMBAY_2013
Sumana Hariharan
 
PHP Basics and Demo HackU
PHP Basics and Demo HackU
Anshu Prateek
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
PHP Programming: Intro
PHP Programming: Intro
Things Lab
 
MIND sweeping introduction to PHP
MIND sweeping introduction to PHP
BUDNET
 
Quick beginner to Lower-Advanced guide/tutorial in PHP
Quick beginner to Lower-Advanced guide/tutorial in PHP
Sanju Sony Kurian
 
PHP Hypertext Preprocessor
PHP Hypertext Preprocessor
adeel990
 
Php introduction with history of php
Php introduction with history of php
pooja bhandari
 
php fundamental
php fundamental
zalatarunk
 

Recently uploaded (20)

MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
High Availability On-Premises FME Flow.pdf
High Availability On-Premises FME Flow.pdf
Safe Software
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
Precisely
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Safe Software
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
High Availability On-Premises FME Flow.pdf
High Availability On-Premises FME Flow.pdf
Safe Software
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
Precisely
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Safe Software
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 

PHP for hacks

  • 1. PHP for hacks Tom Praison [email protected] IIT-Delhi 16-Aug-2012
  • 2. Sample Codes • The sample code is available for download https://github.com/tompraison/php_sample
  • 3. What we need to learn? • Enough PHP to handle simple request • How to talk to backend data store using PHP • How to parse XML/JSON in PHP • How to generate JSON in PHP
  • 4. What is PHP? • Server side language • Very easy to learn • Available on LAMP stack (Linux Apache Mysql PHP) • Does not require any special tools. Create a file with .php extension and your done.
  • 6. Getting Started • You need a local server with PHP enabled. • XAMPP for windows • MAMP for Mac OSx • Linux has it by default
  • 7. Getting Started Create a file hello.php into htdocs and call it like this http://localhost:8888/hello.php <?php $school="iit-delhi"; echo "Hello, World $school"; ?>
  • 8. Basic Syntax • PHP blocks start with <?php and end with ?> - • Every line of PHP has to end with a semicolon ";” • Variables in PHP start with a $ • You print out content to the document in PHP with the echo command. • $school is variable and it can be printed out • You can jump in and out of PHP anywhere in the document. So if you intersperse PHP with HTML blocks, that is totally fine. For example:
  • 9. Mix Match • You can mix and match HTML and PHP <?php $origin = 'Outer Space'; $planet = 'Earth'; $plan = 9; $sceneryType = "awful"; ?> <h1>Synopsis</h1><p>It was a peaceful time on planet <?php echo $planet;?> and people in the <?php echo $sceneryType;?> scenery were unaware of the diabolic plan <?php echo $plan;?> from <?php echo $origin;?> that will take their senses to the edge of what can be endured.</p> demo1.php
  • 10. Displaying more complex data • You can define arrays in PHP using the array() method $lampstack = array('Linux','Apache','MySQL','PHP'); • If you simply want to display a complex datatype like this in PHP for debugging you can use the print_r() command $lampstack = array('Linux','Apache','MySQL','PHP'); print_r($lampstack); demo2.php
  • 11. Arrays • Accessing arrays using index <ul> <?php $lampstack = array('Linux','Apache','MySQL','PHP'); echo '<li>Operating System:'.$lampstack[0] . '</li>'; echo '<li>Server:' . $lampstack[1] . '</li>'; echo '<li>Database:' . $lampstack[2] . '</li>'; echo '<li>Language:' . $lampstack[3] . '</li>'; ?> </ul> demo3.php
  • 12. Arrays • Iterating through arrays <ul> <?php $lampstack = array('Linux','Apache','MySQL','PHP'); $labels = array('Operating System','Server','Database','Language'); $length = sizeof($lampstack); for( $i = 0;$i < $length;$i++ ){ echo '<li>' . $labels[$i] . ':' . $lampstack[$i] . '</li>'; } ?> </ul> sizeof($array) - this will return the size of the array demo4.php
  • 13. Associative Arrays • PHP has associative arrays with string keys <ul> <?php $lampstack = array( 'Operating System' => 'Linux', 'Server' => 'Apache', 'Database' => 'MySQL', 'Language' => 'PHP' ); $length = sizeof($lampstack); $keys = array_keys($lampstack); for( $i = 0;$i < $length;$i++ ){ echo '<li>' . $keys[$i] . ':' . $lampstack[$keys[$i]] . '</li>'; } ?> </ul> demo5.php
  • 14. Functions <?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); ?> demo6.php
  • 15. Interacting with the web - URL parameters <?php $name = 'Tom'; // if there is no language defined, switch to English if( !isset($_GET['language']) ){ $welcome = 'Oh, hello there, '; } if( $_GET['language'] == 'hindi' ){ $welcome = 'Namastae, '; } switch($_GET['font']){ case 'small': $size = 80; break; case 'medium': $size = 100; break; case 'large': $size = 120; break; default: $size = 100; break; } echo '<style>body{font-size:' . $size . '%;}</style>'; echo '<h1>'.$welcome.$name.'</h1>'; ?> demo7.php
  • 16. Loading content from the web <?php // define the URL to load $url = 'http://cricket.yahoo.com/player-profile/Sachin- Tendulkar_2962'; // start cURL $ch = curl_init(); // tell cURL what the URL is curl_setopt($ch, CURLOPT_URL, $url); // tell cURL that you want the data back from that URL curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // run cURL $output = curl_exec($ch); // end the cURL call (this also cleans up memory so it is // important) curl_close($ch); // display the output echo $output; ?> demo8.php
  • 17. Displaying XML content • Demo – Showing Twitter trends given a place – Displaying XML Content – Displaying JSON demo9.php
  • 18. Connecting to MySQL • Demo10.php from source code • Simple example to fetch data from DB
  • 19. Further Reference http://www.php.net/ http://developer.yahoo.com http://isithackday.com/hackday- toolbox/phpforhacks/index.html http://www.slideshare.net/tompraison https://github.com/tompraison/php_sample