SlideShare a Scribd company logo
Introduction to PHP 19 June 2010 Kathy Reid @KathyReid |  [email_address]
What are we going to cover? What PHP is, what it can do and how it differs from HTML How web servers work and the HTTP request-response lifecycle Basic statements in PHP and an introduction to procedural programming and forms and databases overview An overview to common PHP tools How to get more help with PHP
What is PHP? PHP: Hypertext preprocessor Server-side  scripting language (has to be run on a server, not in your browser like Javascript – that's a client-side language) Open source  and free to download (this means that the code behind PHP is freely available - this often means PHP hosting is cheaper than other platforms, such as ASP) Particularly suitable for web applications, but doesn't have to be used for this purpose
What can PHP do? PHP is a general purpose scripting language. This means it can do lots of programming tasks. It is particularly suited to; Adding  dynamic  content to websites Processing HTML  forms Connecting to  databases  and storing, searching and retrieving information from databases Personalising  and  customising  websites
Why should I learn PHP? To grow an evil army of programmers to take over the world MWHAHAHAHAHAHA … but seriously there are some good reasons Easy to learn (difficult to master) Used widely in third party tools – WordPress, Drupal, CiviCRM, Facebook applications etc Becoming much more mature and adopted as an enterprise-level programming language
What do I need  to get started with PHP? Access to a web server with PHP installed This might be through a hosting company, and you would access the server using an FTP program, like  FileZilla . The files would be accessed from a URL like http://myurl.org/myfile.php   If you're more advanced, you might wish to have a go installing PHP on your own computer. There are builds available for Windows, most Linux variants and even MacOS.  http://localhost/myfile.php
What do I need to get started with PHP (cont'd) It helps to have a good understanding of how HTTP works (covered in this tutorial) It helps to have at least a basic understanding of HTML (any version of HTML to be honest) Your text editor of choice.  Syntax highlighting  is a great feature to have in a PHP editor. I use  Eclipse , but there are many others to choose from; http://en.wikipedia.org/wiki/List_of_PHP_editors
Easy to learn,  difficult to master One of the great features of PHP is that it is  easy to learn.  It is also  difficult to master; Writing  maintainable  code Reusable  code (through objects) Designing applications to be  secure Designing for  scalability Designing for  portability  (between different databases and server operating environments) There's always more to learn about PHP!!
Why is PHP different to HTML? HTML is  static <html>   <body>   <h1>Hello world!   </h1>   </body> </html> Will always display 'Hello world!'
Why is PHP different to HTML? (cont'd) PHP is  dynamic <?php    $greeting = 'Hola!'; ?> <html>   <body>   <h1>   <?php echo $greeting; ?>   </h1>   </body> </html> What will this display?
How web servers work So what makes PHP  dynamic ? Web  servers  and  user agents  (browsers) work in what's called a 'client-server' relationship.  The user agent (browser) sends a  request  to the web server The web server interprets that request, and sends a  response  to the web server
How web servers work (cont'd) User agent Browser – such as Firefox, Internet Explorer, Safari – on a computer, mobile phone, iPhone or iPad etc Issues  requests  to a web server For example, going to this URL in your browser http://www.example.com/index.php causes the browser to issue this  request: GET /index.php HTTP/1.1 Host: www.example.com
How web servers work (con'td) Web server Many varieties of web server – such as IIS (Internet information services), Apache httpd etc.  PHP is primarily used with Apache httpd, but can be used with IIS Interprets  requests  from a user agent, acts on them and issues  responses For example, a web server may respond to the previous request with this:
How web servers work (cont'd) <html> <body> <h1>My index page</h1> <p>This is the content on the index page!</p> </body> </html>
How web servers work (cont'd) The browser then interprets the  request , which is usually in HTML format, and  renders  the HTML on screen. This is why the same  HTML  can look different between different browsers – for instance Firefox and Internet Explorer – because the  rendering   engines  inside the browsers are different. This is a key source of frustration for web developers!
How PHP works  with the web server Okay, so we've seen how HTTP  requests  and  responses  work. But this is exactly how HTML works! How does PHP come into it? Before the web server (for example Apache) issues the response, the PHP interpreter is invoked and processes the information in the PHP script. This is why PHP files are called 'filename.php' and normal (static) html files are called 'filename.html' – it helps the web server determine whether to invoke the PHP interpreter or not.
How PHP works  with the web server (cont'd) For example, let's say I put this code in a file; <html>   <body>   <h1>   <?php echo date(&quot;F j, Y, g:i a&quot;);  ?>   </h1>   </body> </html> …  and I call the file 'something.  html ' What will be displayed on the page?
How PHP works  with the web server (cont'd) Rather than the current date and time, it will display something like this; <?php echo date(&quot;F j, Y, g:i a&quot;);  ?> This is because the PHP interpreter was  not   invoked  due to the file being named  something.html  – the PHP script is not interpreted, and values substituted before the web server issued the response!
How PHP works  with the web server (cont'd) If on the other hand, the file was named something. php , the PHP interpreter would be invoked and you would see something similar to; June 19, 2010, 2.30 pm This is because the PHP interpreter was  invoked , and the PHP script processed before the  response  was sent to the  user agent.
Quick recap before we take a look at some code PHP is a  dynamic  scripting language generally used with a web server User agents  (browsers) issue  requests  to web servers. Web servers process these requests. They may  invoke  the PHP interpreter. The web server then issues a  response  back to the user agent, usually in HTML. The user agent then  renders  the HTML, and that's why we see a web page :-)
PHP Basics: Variables Examples of declaring variables in PHP <?php $myString = 'Hello world'; $myInt = 999; $myFloat = 12345; $myArray = array(); $myObject = new someObject(); ?>
PHP Basics: Variables Variables in PHP don't have to be  explicitly  declared – but it is best practice to do so for readability and for debugging Variables in PHP are  loosely   typed  – the type of value is not stated when the variable is declared – it is implicit. This can also be difficult to debug – as variables can unknowingly be  cast  into different types – with unexpected results!
PHP Basics: Variables Basic example. What might happen with  $total  being declared implicitly here? <?php $cost = 10; // declared explicitly $units = 5; // declared explicitly // do some stuff in here $total = $cost * $units; // implicit ?>
PHP Basics: Control structures Control structures alter the  flow of execution  of a PHP script.  if...then...else If something is true, do x, else do y While ... While something is true, keep doing x Switch If the condition is a, do action for a
PHP Basics: Control structures try...throw...catch Try  to do something, but if the something fails, then  throw  an error. The error can then be  caught  and processed, such as by displaying an appropriate error message This is a more advanced control structure, but it is very worthwhile learning, particularly if you plan to use object oriented programming.
PHP Basics: Arrays Arrays in PHP are incredibly powerful. There are a large number of array functions available to choose from. Arrays in PHP are essentially collections of  key-value pairs . In some programming languages, the key is always a number. In PHP, the key can be a string or a number. This is referred to as an  associative array .
PHP Basics: Arrays <?php $array1 = array(10, 20, 40, 80, 160); $array2 = array('banana', 'pear', 'apricot'); $array3 = array(0 => 4, 3 => 3838); $array4 = array('beans' => 'borlotti', 'icecream' => 'chocolate'); ?> my
PHP Basics: Working with forms One of the common uses for PHP is to process web based forms. When a HTML form is submitted to a PHP script, a number of variables are made available to PHP. To make a HTML form submit to a PHP script, the path to the PHP script has to be given in the FORM element; <form name=&quot;myForm&quot; action=&quot;/myscript.php/&quot;>
PHP Basics: Working with forms Once the form has been submitted, the values will be available in $_POST superglobal array. We can iterate through this array to process the form, send emails etc. <form name=&quot;myForm&quot; action=&quot;/myscript.php/&quot;>   <input type=”text” name=”myTextField”> </form>
PHP Basics: Working with forms The data from this input field will be available in the variable; $_POST['myTextField'] This data can then be used for instance to put into an email, insert into a database etc.
PHP Basics: Working with databases PHP can connect to a database using functions specific to the database For example MySQL Database connection usually requires username, password and database name Not enough time here to cover all database concepts, but can cover a brief introduction to database theory if you'd like?
Commonly used  free and open source software which utilises PHP Wordpress – blogging and content management software http://www.wordpress.org Drupal – content management software http://www.drupal.org PHPMyAdmin – provides an easy to use web interface to MySQL databases  http://www.phpmyadmin.net
Commonly used  free and open source software which utilises PHP (cont'd) Zen Cart – online shopping cart http://www.zen-cart.com   Moodle – Learning Management Software http://www.moodle.org   Mahara – e-Portfolios  http://www.mahara.org Media Wiki – wiki software http://www.mediawiki.org
PHP frameworks A  framework  is basically a collection of components that make development easier by abstracting commonly used functions. The developer can then focus on the 'core features' of the application they are creating, rather than worrying about formatting, database connections etc http://en.wikipedia.org/wiki/Comparison_of_web_application_frameworks#PHP_2 Examples include Zend, Symfony
More information and resources What is PHP? http://au.php.net/manual/en/intro-whatis.php   What can PHP do? http://au.php.net/manual/en/intro-whatcando.php Introductory tutorial (from PHP.net) http://au.php.net/manual/en/tutorial.php
More information and resources (cont'd) Other good introductory tutorials (mostly from Slideshare) http://www.slideshare.net/cwarren/introduction-to-php-for-wit2009 http://www.slideshare.net/alexjones89/an-introduction-to-php http://www.slideshare.net/binnyva/php-the-easiest-language-to-learn-presentation
User groups PHP Melbourne http://phpmelb.org/ irc://freenode/phpmelb PHPWomen  (XY welcome, we exist to be inclusive and help support women in learning and mastering PHP) http://www.phpwomen.org irc://freenode/phpmelb @PHPWomen on Twitter
Related user groups and developer communities Melbourne WordPress group http://groups.google.com/group/wpubmelb Melbourne Drupal group http://groups.drupal.org/australia Melbourne MySQL user group http://lists.mysql.com/ug-melbourne?sub=1

More Related Content

What's hot

Php Tutorial
Php TutorialPhp Tutorial
1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master
jeeva indra
 
Php introduction and configuration
Php introduction and configurationPhp introduction and configuration
Php introduction and configuration
Vijay Kumar Verma
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
Niit
 
Enterprise PHP (php|works 2008)
Enterprise PHP (php|works 2008)Enterprise PHP (php|works 2008)
Enterprise PHP (php|works 2008)
Ivo Jansch
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)
Arjun Shanka
 
Php tutorial
Php  tutorialPhp  tutorial
Php
PhpPhp
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
justmeanscsr
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
justmeanscsr
 

What's hot (10)

Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master
 
Php introduction and configuration
Php introduction and configurationPhp introduction and configuration
Php introduction and configuration
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Enterprise PHP (php|works 2008)
Enterprise PHP (php|works 2008)Enterprise PHP (php|works 2008)
Enterprise PHP (php|works 2008)
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)
 
Php tutorial
Php  tutorialPhp  tutorial
Php tutorial
 
Php
PhpPhp
Php
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 

Similar to Intro to-php-19 jun10

Php tizag tutorial
Php tizag tutorialPhp tizag tutorial
Php tizag tutorial
Pradeep Kumar
 
php_tizag_tutorial
php_tizag_tutorialphp_tizag_tutorial
php_tizag_tutorial
tutorialsruby
 
PHP learning
PHP learningPHP learning
PHP learning
Self-Employed
 
Php tizag tutorial
Php tizag tutorialPhp tizag tutorial
Php tizag tutorial
PrinceGuru MS
 
Php tizag tutorial
Php tizag tutorial Php tizag tutorial
Php tizag tutorial
jaggu536
 
Php1
Php1Php1
Php1
Php1Php1
Php1
Php1Php1
Php
PhpPhp
Php notes 01
Php notes 01Php notes 01
Php notes 01
Aakaash Ngl
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
Vibrant Technologies & Computers
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
php basics
php basicsphp basics
php basics
NIRMAL FELIX
 
PHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERSPHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERS
Aminiel Michael
 
How to Use PHP in HTML.pdf
How to Use PHP in HTML.pdfHow to Use PHP in HTML.pdf
How to Use PHP in HTML.pdf
CIOWomenMagazine
 
IT Club @ NCP - PHP Workshop May 10, 2011
IT Club @ NCP - PHP Workshop May 10, 2011IT Club @ NCP - PHP Workshop May 10, 2011
IT Club @ NCP - PHP Workshop May 10, 2011
IT Club GTA
 
10_introduction_php.ppt
10_introduction_php.ppt10_introduction_php.ppt
10_introduction_php.ppt
GiyaShefin
 
PHP.pptx is the Best Explanation of ppts
PHP.pptx is the Best Explanation of pptsPHP.pptx is the Best Explanation of ppts
PHP.pptx is the Best Explanation of ppts
AkhileshPansare
 
introduction_php.ppt
introduction_php.pptintroduction_php.ppt
introduction_php.ppt
ArunKumar313658
 

Similar to Intro to-php-19 jun10 (20)

Php tizag tutorial
Php tizag tutorialPhp tizag tutorial
Php tizag tutorial
 
php_tizag_tutorial
php_tizag_tutorialphp_tizag_tutorial
php_tizag_tutorial
 
PHP learning
PHP learningPHP learning
PHP learning
 
Php tizag tutorial
Php tizag tutorialPhp tizag tutorial
Php tizag tutorial
 
Php tizag tutorial
Php tizag tutorial Php tizag tutorial
Php tizag tutorial
 
Php1
Php1Php1
Php1
 
Php1
Php1Php1
Php1
 
Php1
Php1Php1
Php1
 
Php
PhpPhp
Php
 
Php notes 01
Php notes 01Php notes 01
Php notes 01
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
 
php basics
php basicsphp basics
php basics
 
PHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERSPHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERS
 
How to Use PHP in HTML.pdf
How to Use PHP in HTML.pdfHow to Use PHP in HTML.pdf
How to Use PHP in HTML.pdf
 
IT Club @ NCP - PHP Workshop May 10, 2011
IT Club @ NCP - PHP Workshop May 10, 2011IT Club @ NCP - PHP Workshop May 10, 2011
IT Club @ NCP - PHP Workshop May 10, 2011
 
10_introduction_php.ppt
10_introduction_php.ppt10_introduction_php.ppt
10_introduction_php.ppt
 
PHP.pptx is the Best Explanation of ppts
PHP.pptx is the Best Explanation of pptsPHP.pptx is the Best Explanation of ppts
PHP.pptx is the Best Explanation of ppts
 
introduction_php.ppt
introduction_php.pptintroduction_php.ppt
introduction_php.ppt
 

More from Kathy Reid

Software Freedom Day Melbourne 2013 - Building free software communities
Software Freedom Day Melbourne 2013 - Building free software communitiesSoftware Freedom Day Melbourne 2013 - Building free software communities
Software Freedom Day Melbourne 2013 - Building free software communities
Kathy Reid
 
BarCampGeelong 9th July 2011 - Welcome Presentation
BarCampGeelong 9th July 2011 - Welcome PresentationBarCampGeelong 9th July 2011 - Welcome Presentation
BarCampGeelong 9th July 2011 - Welcome Presentation
Kathy Reid
 
Not your Nanna's knitting: My first Lilypad Arduino project
Not your Nanna's knitting: My first Lilypad Arduino projectNot your Nanna's knitting: My first Lilypad Arduino project
Not your Nanna's knitting: My first Lilypad Arduino project
Kathy Reid
 
Deakin Uni - Videoconferencing journey
Deakin Uni - Videoconferencing journeyDeakin Uni - Videoconferencing journey
Deakin Uni - Videoconferencing journey
Kathy Reid
 
Advanced WordPress
Advanced WordPressAdvanced WordPress
Advanced WordPress
Kathy Reid
 
Introduction to CiviCRM 12 Sep 09
Introduction to CiviCRM 12 Sep 09Introduction to CiviCRM 12 Sep 09
Introduction to CiviCRM 12 Sep 09
Kathy Reid
 
Introduction to WordPress
Introduction to WordPressIntroduction to WordPress
Introduction to WordPress
Kathy Reid
 
Making something out of nothing: Free software for non-profit organisations
Making something out of nothing: Free software for non-profit organisationsMaking something out of nothing: Free software for non-profit organisations
Making something out of nothing: Free software for non-profit organisations
Kathy Reid
 

More from Kathy Reid (8)

Software Freedom Day Melbourne 2013 - Building free software communities
Software Freedom Day Melbourne 2013 - Building free software communitiesSoftware Freedom Day Melbourne 2013 - Building free software communities
Software Freedom Day Melbourne 2013 - Building free software communities
 
BarCampGeelong 9th July 2011 - Welcome Presentation
BarCampGeelong 9th July 2011 - Welcome PresentationBarCampGeelong 9th July 2011 - Welcome Presentation
BarCampGeelong 9th July 2011 - Welcome Presentation
 
Not your Nanna's knitting: My first Lilypad Arduino project
Not your Nanna's knitting: My first Lilypad Arduino projectNot your Nanna's knitting: My first Lilypad Arduino project
Not your Nanna's knitting: My first Lilypad Arduino project
 
Deakin Uni - Videoconferencing journey
Deakin Uni - Videoconferencing journeyDeakin Uni - Videoconferencing journey
Deakin Uni - Videoconferencing journey
 
Advanced WordPress
Advanced WordPressAdvanced WordPress
Advanced WordPress
 
Introduction to CiviCRM 12 Sep 09
Introduction to CiviCRM 12 Sep 09Introduction to CiviCRM 12 Sep 09
Introduction to CiviCRM 12 Sep 09
 
Introduction to WordPress
Introduction to WordPressIntroduction to WordPress
Introduction to WordPress
 
Making something out of nothing: Free software for non-profit organisations
Making something out of nothing: Free software for non-profit organisationsMaking something out of nothing: Free software for non-profit organisations
Making something out of nothing: Free software for non-profit organisations
 

Recently uploaded

Dublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptx
Dublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptxDublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptx
Dublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptx
Kunal Gupta
 
Calgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptxCalgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptx
ishalveerrandhawa1
 
WPRiders Company Presentation Slide Deck
WPRiders Company Presentation Slide DeckWPRiders Company Presentation Slide Deck
WPRiders Company Presentation Slide Deck
Lidia A.
 
Password Rotation in 2024 is still Relevant
Password Rotation in 2024 is still RelevantPassword Rotation in 2024 is still Relevant
Password Rotation in 2024 is still Relevant
Bert Blevins
 
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdfWhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
ArgaBisma
 
DealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 editionDealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 edition
Yevgen Sysoyev
 
How Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdfHow Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdf
HackersList
 
Best Practices for Effectively Running dbt in Airflow.pdf
Best Practices for Effectively Running dbt in Airflow.pdfBest Practices for Effectively Running dbt in Airflow.pdf
Best Practices for Effectively Running dbt in Airflow.pdf
Tatiana Al-Chueyr
 
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
maigasapphire
 
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
Priyanka Aash
 
How RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptxHow RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptx
SynapseIndia
 
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
aslasdfmkhan4750
 
Observability For You and Me with OpenTelemetry
Observability For You and Me with OpenTelemetryObservability For You and Me with OpenTelemetry
Observability For You and Me with OpenTelemetry
Eric D. Schabell
 
Applying Retrieval-Augmented Generation (RAG) to Combat Hallucinations in GenAI
Applying Retrieval-Augmented Generation (RAG) to Combat Hallucinations in GenAIApplying Retrieval-Augmented Generation (RAG) to Combat Hallucinations in GenAI
Applying Retrieval-Augmented Generation (RAG) to Combat Hallucinations in GenAI
ssuserd4e0d2
 
How to build a generative AI solution A step-by-step guide (2).pdf
How to build a generative AI solution A step-by-step guide (2).pdfHow to build a generative AI solution A step-by-step guide (2).pdf
How to build a generative AI solution A step-by-step guide (2).pdf
ChristopherTHyatt
 
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptxUse Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
SynapseIndia
 
Three New Criminal Laws in India 1 July 2024
Three New Criminal Laws in India 1 July 2024Three New Criminal Laws in India 1 July 2024
Three New Criminal Laws in India 1 July 2024
aakash malhotra
 
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
Kief Morris
 
Using LLM Agents with Llama 3, LangGraph and Milvus
Using LLM Agents with Llama 3, LangGraph and MilvusUsing LLM Agents with Llama 3, LangGraph and Milvus
Using LLM Agents with Llama 3, LangGraph and Milvus
Zilliz
 
Recent Advancements in the NIST-JARVIS Infrastructure
Recent Advancements in the NIST-JARVIS InfrastructureRecent Advancements in the NIST-JARVIS Infrastructure
Recent Advancements in the NIST-JARVIS Infrastructure
KAMAL CHOUDHARY
 

Recently uploaded (20)

Dublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptx
Dublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptxDublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptx
Dublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptx
 
Calgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptxCalgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptx
 
WPRiders Company Presentation Slide Deck
WPRiders Company Presentation Slide DeckWPRiders Company Presentation Slide Deck
WPRiders Company Presentation Slide Deck
 
Password Rotation in 2024 is still Relevant
Password Rotation in 2024 is still RelevantPassword Rotation in 2024 is still Relevant
Password Rotation in 2024 is still Relevant
 
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdfWhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
 
DealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 editionDealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 edition
 
How Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdfHow Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdf
 
Best Practices for Effectively Running dbt in Airflow.pdf
Best Practices for Effectively Running dbt in Airflow.pdfBest Practices for Effectively Running dbt in Airflow.pdf
Best Practices for Effectively Running dbt in Airflow.pdf
 
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
 
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
 
How RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptxHow RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptx
 
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
 
Observability For You and Me with OpenTelemetry
Observability For You and Me with OpenTelemetryObservability For You and Me with OpenTelemetry
Observability For You and Me with OpenTelemetry
 
Applying Retrieval-Augmented Generation (RAG) to Combat Hallucinations in GenAI
Applying Retrieval-Augmented Generation (RAG) to Combat Hallucinations in GenAIApplying Retrieval-Augmented Generation (RAG) to Combat Hallucinations in GenAI
Applying Retrieval-Augmented Generation (RAG) to Combat Hallucinations in GenAI
 
How to build a generative AI solution A step-by-step guide (2).pdf
How to build a generative AI solution A step-by-step guide (2).pdfHow to build a generative AI solution A step-by-step guide (2).pdf
How to build a generative AI solution A step-by-step guide (2).pdf
 
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptxUse Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
 
Three New Criminal Laws in India 1 July 2024
Three New Criminal Laws in India 1 July 2024Three New Criminal Laws in India 1 July 2024
Three New Criminal Laws in India 1 July 2024
 
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
 
Using LLM Agents with Llama 3, LangGraph and Milvus
Using LLM Agents with Llama 3, LangGraph and MilvusUsing LLM Agents with Llama 3, LangGraph and Milvus
Using LLM Agents with Llama 3, LangGraph and Milvus
 
Recent Advancements in the NIST-JARVIS Infrastructure
Recent Advancements in the NIST-JARVIS InfrastructureRecent Advancements in the NIST-JARVIS Infrastructure
Recent Advancements in the NIST-JARVIS Infrastructure
 

Intro to-php-19 jun10

  • 1. Introduction to PHP 19 June 2010 Kathy Reid @KathyReid | [email_address]
  • 2. What are we going to cover? What PHP is, what it can do and how it differs from HTML How web servers work and the HTTP request-response lifecycle Basic statements in PHP and an introduction to procedural programming and forms and databases overview An overview to common PHP tools How to get more help with PHP
  • 3. What is PHP? PHP: Hypertext preprocessor Server-side scripting language (has to be run on a server, not in your browser like Javascript – that's a client-side language) Open source and free to download (this means that the code behind PHP is freely available - this often means PHP hosting is cheaper than other platforms, such as ASP) Particularly suitable for web applications, but doesn't have to be used for this purpose
  • 4. What can PHP do? PHP is a general purpose scripting language. This means it can do lots of programming tasks. It is particularly suited to; Adding dynamic content to websites Processing HTML forms Connecting to databases and storing, searching and retrieving information from databases Personalising and customising websites
  • 5. Why should I learn PHP? To grow an evil army of programmers to take over the world MWHAHAHAHAHAHA … but seriously there are some good reasons Easy to learn (difficult to master) Used widely in third party tools – WordPress, Drupal, CiviCRM, Facebook applications etc Becoming much more mature and adopted as an enterprise-level programming language
  • 6. What do I need to get started with PHP? Access to a web server with PHP installed This might be through a hosting company, and you would access the server using an FTP program, like FileZilla . The files would be accessed from a URL like http://myurl.org/myfile.php If you're more advanced, you might wish to have a go installing PHP on your own computer. There are builds available for Windows, most Linux variants and even MacOS. http://localhost/myfile.php
  • 7. What do I need to get started with PHP (cont'd) It helps to have a good understanding of how HTTP works (covered in this tutorial) It helps to have at least a basic understanding of HTML (any version of HTML to be honest) Your text editor of choice. Syntax highlighting is a great feature to have in a PHP editor. I use Eclipse , but there are many others to choose from; http://en.wikipedia.org/wiki/List_of_PHP_editors
  • 8. Easy to learn, difficult to master One of the great features of PHP is that it is easy to learn. It is also difficult to master; Writing maintainable code Reusable code (through objects) Designing applications to be secure Designing for scalability Designing for portability (between different databases and server operating environments) There's always more to learn about PHP!!
  • 9. Why is PHP different to HTML? HTML is static <html> <body> <h1>Hello world! </h1> </body> </html> Will always display 'Hello world!'
  • 10. Why is PHP different to HTML? (cont'd) PHP is dynamic <?php $greeting = 'Hola!'; ?> <html> <body> <h1> <?php echo $greeting; ?> </h1> </body> </html> What will this display?
  • 11. How web servers work So what makes PHP dynamic ? Web servers and user agents (browsers) work in what's called a 'client-server' relationship. The user agent (browser) sends a request to the web server The web server interprets that request, and sends a response to the web server
  • 12. How web servers work (cont'd) User agent Browser – such as Firefox, Internet Explorer, Safari – on a computer, mobile phone, iPhone or iPad etc Issues requests to a web server For example, going to this URL in your browser http://www.example.com/index.php causes the browser to issue this request: GET /index.php HTTP/1.1 Host: www.example.com
  • 13. How web servers work (con'td) Web server Many varieties of web server – such as IIS (Internet information services), Apache httpd etc. PHP is primarily used with Apache httpd, but can be used with IIS Interprets requests from a user agent, acts on them and issues responses For example, a web server may respond to the previous request with this:
  • 14. How web servers work (cont'd) <html> <body> <h1>My index page</h1> <p>This is the content on the index page!</p> </body> </html>
  • 15. How web servers work (cont'd) The browser then interprets the request , which is usually in HTML format, and renders the HTML on screen. This is why the same HTML can look different between different browsers – for instance Firefox and Internet Explorer – because the rendering engines inside the browsers are different. This is a key source of frustration for web developers!
  • 16. How PHP works with the web server Okay, so we've seen how HTTP requests and responses work. But this is exactly how HTML works! How does PHP come into it? Before the web server (for example Apache) issues the response, the PHP interpreter is invoked and processes the information in the PHP script. This is why PHP files are called 'filename.php' and normal (static) html files are called 'filename.html' – it helps the web server determine whether to invoke the PHP interpreter or not.
  • 17. How PHP works with the web server (cont'd) For example, let's say I put this code in a file; <html> <body> <h1> <?php echo date(&quot;F j, Y, g:i a&quot;); ?> </h1> </body> </html> … and I call the file 'something. html ' What will be displayed on the page?
  • 18. How PHP works with the web server (cont'd) Rather than the current date and time, it will display something like this; <?php echo date(&quot;F j, Y, g:i a&quot;); ?> This is because the PHP interpreter was not invoked due to the file being named something.html – the PHP script is not interpreted, and values substituted before the web server issued the response!
  • 19. How PHP works with the web server (cont'd) If on the other hand, the file was named something. php , the PHP interpreter would be invoked and you would see something similar to; June 19, 2010, 2.30 pm This is because the PHP interpreter was invoked , and the PHP script processed before the response was sent to the user agent.
  • 20. Quick recap before we take a look at some code PHP is a dynamic scripting language generally used with a web server User agents (browsers) issue requests to web servers. Web servers process these requests. They may invoke the PHP interpreter. The web server then issues a response back to the user agent, usually in HTML. The user agent then renders the HTML, and that's why we see a web page :-)
  • 21. PHP Basics: Variables Examples of declaring variables in PHP <?php $myString = 'Hello world'; $myInt = 999; $myFloat = 12345; $myArray = array(); $myObject = new someObject(); ?>
  • 22. PHP Basics: Variables Variables in PHP don't have to be explicitly declared – but it is best practice to do so for readability and for debugging Variables in PHP are loosely typed – the type of value is not stated when the variable is declared – it is implicit. This can also be difficult to debug – as variables can unknowingly be cast into different types – with unexpected results!
  • 23. PHP Basics: Variables Basic example. What might happen with $total being declared implicitly here? <?php $cost = 10; // declared explicitly $units = 5; // declared explicitly // do some stuff in here $total = $cost * $units; // implicit ?>
  • 24. PHP Basics: Control structures Control structures alter the flow of execution of a PHP script. if...then...else If something is true, do x, else do y While ... While something is true, keep doing x Switch If the condition is a, do action for a
  • 25. PHP Basics: Control structures try...throw...catch Try to do something, but if the something fails, then throw an error. The error can then be caught and processed, such as by displaying an appropriate error message This is a more advanced control structure, but it is very worthwhile learning, particularly if you plan to use object oriented programming.
  • 26. PHP Basics: Arrays Arrays in PHP are incredibly powerful. There are a large number of array functions available to choose from. Arrays in PHP are essentially collections of key-value pairs . In some programming languages, the key is always a number. In PHP, the key can be a string or a number. This is referred to as an associative array .
  • 27. PHP Basics: Arrays <?php $array1 = array(10, 20, 40, 80, 160); $array2 = array('banana', 'pear', 'apricot'); $array3 = array(0 => 4, 3 => 3838); $array4 = array('beans' => 'borlotti', 'icecream' => 'chocolate'); ?> my
  • 28. PHP Basics: Working with forms One of the common uses for PHP is to process web based forms. When a HTML form is submitted to a PHP script, a number of variables are made available to PHP. To make a HTML form submit to a PHP script, the path to the PHP script has to be given in the FORM element; <form name=&quot;myForm&quot; action=&quot;/myscript.php/&quot;>
  • 29. PHP Basics: Working with forms Once the form has been submitted, the values will be available in $_POST superglobal array. We can iterate through this array to process the form, send emails etc. <form name=&quot;myForm&quot; action=&quot;/myscript.php/&quot;> <input type=”text” name=”myTextField”> </form>
  • 30. PHP Basics: Working with forms The data from this input field will be available in the variable; $_POST['myTextField'] This data can then be used for instance to put into an email, insert into a database etc.
  • 31. PHP Basics: Working with databases PHP can connect to a database using functions specific to the database For example MySQL Database connection usually requires username, password and database name Not enough time here to cover all database concepts, but can cover a brief introduction to database theory if you'd like?
  • 32. Commonly used free and open source software which utilises PHP Wordpress – blogging and content management software http://www.wordpress.org Drupal – content management software http://www.drupal.org PHPMyAdmin – provides an easy to use web interface to MySQL databases http://www.phpmyadmin.net
  • 33. Commonly used free and open source software which utilises PHP (cont'd) Zen Cart – online shopping cart http://www.zen-cart.com Moodle – Learning Management Software http://www.moodle.org Mahara – e-Portfolios http://www.mahara.org Media Wiki – wiki software http://www.mediawiki.org
  • 34. PHP frameworks A framework is basically a collection of components that make development easier by abstracting commonly used functions. The developer can then focus on the 'core features' of the application they are creating, rather than worrying about formatting, database connections etc http://en.wikipedia.org/wiki/Comparison_of_web_application_frameworks#PHP_2 Examples include Zend, Symfony
  • 35. More information and resources What is PHP? http://au.php.net/manual/en/intro-whatis.php What can PHP do? http://au.php.net/manual/en/intro-whatcando.php Introductory tutorial (from PHP.net) http://au.php.net/manual/en/tutorial.php
  • 36. More information and resources (cont'd) Other good introductory tutorials (mostly from Slideshare) http://www.slideshare.net/cwarren/introduction-to-php-for-wit2009 http://www.slideshare.net/alexjones89/an-introduction-to-php http://www.slideshare.net/binnyva/php-the-easiest-language-to-learn-presentation
  • 37. User groups PHP Melbourne http://phpmelb.org/ irc://freenode/phpmelb PHPWomen (XY welcome, we exist to be inclusive and help support women in learning and mastering PHP) http://www.phpwomen.org irc://freenode/phpmelb @PHPWomen on Twitter
  • 38. Related user groups and developer communities Melbourne WordPress group http://groups.google.com/group/wpubmelb Melbourne Drupal group http://groups.drupal.org/australia Melbourne MySQL user group http://lists.mysql.com/ug-melbourne?sub=1