First Steps in PHP Creating Very Simple PHP Scripts SoftUni Team Technical Trainers Software University

Slides:



Advertisements
Similar presentations
JavaScript Basics Course Introduction SoftUni Team Technical Trainers Software University
Advertisements

C# Advanced Topics Methods, Classes and Objects SoftUni Team Technical Trainers Software University
AngularJS Routing Routes, Route Parameters, Templates, Location, Navigation SoftUni Team Technical Trainers Software University
PHP Flow Control Loops, Functions, Return, Exit, Require, Try...Catch Software University SoftUni Team Technical Trainers.
AngularJS Services Built-in and Custom Services SoftUni Team Technical Trainers Software University
Methods Writing and using methods, overloads, ref, out SoftUni Team Technical Trainers Software University
Software University Curriculum, Courses, Exams, Jobs SoftUni Team Technical Trainers Software University
PHP Basics Course Introduction SoftUni Team Technical Trainers Software University
Fundamentals SoftUni Welcome to Software University SoftUni Team Technical Trainers Software University
Project Tracking Tools Trello, Asana, Basecamp, GitHub Issue Tracker, TRAC SoftUni Team Technical Trainers Software University
AngularJS Directives Defining Custom Directives SoftUni Team Technical Trainers Software University
Software Testing Lifecycle Exit Criteria Evaluation, Continuous Integration Ivan Yonkov Technical Trainer Software University.
Fundamentals SoftUni Welcome to Software University SoftUni Team Technical Trainers Software University
Loops Repeating Code Multiple Times SoftUni Team Technical Trainers Software University
Start Your Own Blog Angel Georgiev Part-time Trainer angeru.softuni-friends.org Software University The Culture of Knowledge Sharing.
MVC Advanced & Reflection Reflection, Parsing Dynamic Data, Asynchronous Requests SoftUni Team Technical Trainers Software University
Database APIs and Wrappers
Entity Framework Performance SoftUni Team Technical Trainers Software University
Svetlin Nakov Technical Trainer Software University
Processing Redis with.NET How to Operate with Redis Databases SoftUni Team Technical Trainers Software University
Multidimensional Arrays, Sets, Dictionaries Processing Matrices, Multidimensional Arrays, Dictionaries, Sets SoftUni Team Technical Trainers Software University.
Project Tracking Tools Trello, Asana, Basecamp, GitHub Issue Tracker, TRAC Angel Georgiev Part-time Trainer Software University
Test-Driven Development Learn the "Test First" Approach to Coding SoftUni Team Technical Trainers Software University
Functions Reusable Parts of Code SoftUni Team Technical Trainers Software University
JavaScript Basics Course Introduction Svetlin Nakov Technical Trainer Software University
Trainers Team Ivan Yonkov Rated in the top 7% at Stack Overflow
Templating, Routing, lodash Extending functionality using Collections SoftUni Team Technical Trainers Software University
Arrays, Lists, Stacks, Queues Processing Sequences of Elements SoftUni Team Technical Trainers Software University
AMD and RequireJS Splitting JavaScript Code into Dependent Modules Software University Technical Trainers SoftUni Team.
Asynchronous Web Services Writing Asynchronous Web Services SoftUni Team Technical Trainers Software University
SASS & LESS Syntactically Awesome StyleSheets Dynamic StyleSheet Language Svetlin Nakov Technical Trainer Software University
C# Basics Course Introduction Svetlin Nakov Technical Trainer Software University
Sessions and Cookies State Management, Cookies, Sessions, Hidden Fields SoftUni Team Technical Trainers Software University
Jekyll Static Site Generator Template-Based Site Generation Svetlin Nakov Technical Trainer Software University
Forms Overview, Query string, Submitting arrays, PHP & HTML, Input types, Redirecting the user Mario Peshev Technical Trainer Software.
Web Development Tools Tools for Front-End Developers Writing HTML and CSS Code SoftUni Team Technical Trainers Software University
Working with Forms in PHP HTTP GET / POST, Validation, Escaping, Input Types, Submitting Arrays, URL Redirecting, PHP Superglobals Svetlin Nakov Technical.
Exam Preparation Algorithms Course: Sample Exam SoftUni Team Technical Trainers Software University
Tables, Rows, Columns, Cells, Header, Footer, Colspan, Rowspan
CSS Transitions and Animations Animated HTML Elements SoftUni Team Technical Trainers Software University
High-Quality Code: Course Introduction Course Introduction SoftUni Team Technical Trainers Software University
Advanced C# Course Introduction SoftUni Team Technical Trainers Software University
Events Event Handling in JavaScript SoftUni Team Technical Trainers Software University
Mocking with Moq Tools for Easier Unit Testing SoftUni Team Technical Trainers Software University
Mocking with Moq Mocking tools for easier unit testing Svetlin Nakov Technical Trainer Software University
JavaScript Tools Tools for Writing / Editing / Debugging JavaScript Code Svetlin Nakov Technical Trainer Software University
ORM Basics Repository Pattern, Models, Entity Manager Ivan Yonkov Technical Trainer Software University
Test-Driven Development Learn the "Test First" Approach to Coding Svetlin Nakov Technical Trainer Software University
Programming for Beginners Course Introduction SoftUni Team Technical Trainers Software University
Sets, Dictionaries SoftUni Team Technical Trainers Software University
Creating Content Defining Topic, Creating Technical Training Materials SoftUni Team Technical Trainers Software University
High-Quality Code: Course Introduction Course Introduction SoftUni Team Technical Trainers Software University
PHP Basics Course Introduction Svetlin Nakov Technical Trainer Software University
Software Technologies Course Overview SoftUni Team Technical Trainers Software University
Programming Fundamentals Course Introduction SoftUni Team Technical Trainers Software University
Doctrine The PHP ORM SoftUni Team Technical Trainers Software University
Team Work and Personal Skills Course Introduction Angel Georgiev Part-time Trainer Software University
Creating Content Defining Topic, Creating Technical Training Materials SoftUni Team Technical Trainers Software University
Inheritance Class Hierarchies SoftUni Team Technical Trainers Software University
Static Members Static Variables & Methods SoftUni Team Technical Trainers Software University
Stacks and Queues Processing Sequences of Elements SoftUni Team Technical Trainers Software University
Generics SoftUni Team Technical Trainers Software University
Java OOP Advanced Course Introduction SoftUni Team Technical Trainers Software University
Introduction to MVC SoftUni Team Introduction to MVC
State Management Cookies, Sessions SoftUni Team State Management
PHP MVC Frameworks MVC Fundamentals SoftUni Team Technical Trainers
PHP: Introduction Syntax, Basic Web, Forms SoftUni Team PHP
Arrays and Multidimensional Arrays
Extending functionality using Collections
Conditional Statements, Loops, Exit, Require
Presentation transcript:

First Steps in PHP Creating Very Simple PHP Scripts SoftUni Team Technical Trainers Software University

Table of Contents  What is PHP?  First PHP Script: Hello PHP  Variables, Conditions, Loops  Loops: Numbers 1 to 20  Generate Color Palette  HTML Forms with PHP  Hello, Person  Sum Two Numbers 2

3 sli.do #3769 Have a Question?

4  PHP (PHP Hypertext Preprocessor)  Server-side scripting language for building dynamic Web sites  PHP code is embedded in HTML pages  Rendered to HTML at the Web server What is PHP? <ul> </ul> This is PHP code This is HTML code

5  Write PHP script to print "Hello PHP!" Problem: Hello PHP Check your solution here: <?php echo "Hello, PHP!"; echo "Hello, PHP!";?> hello.php

6  Variables in PHP are prefixed by $, e.g. $count  Not declared, created at first assignment  Variables have type, but it is not explicitly specified Variables in PHP echo $count; // Notice: Undefined variable: count $count = 20; // variable $count, value 20 ( integer ) echo $count. ' '; // 20 echo $count. ' '; // 20 echo gettype($count); // integer var_dump($count); // int 20

7  Checking whether a variable exists  isset(variable)  Deleting an existing variable  unset(variable) Variables in PHP (2) $count = 20; if (isset($count)) echo $count; // 20 echo $count; // 20 unset($count); echo $count; // Notice: Undefined variable: count

8  PHP supports if - else and switch - case like C#, Java and JS Conditions in PHP = 6 && $month = 6 && $month It is, a summer time! It is, a summer time! Sorry, not summer. Sorry, not summer.

9  PHP supports while, do - while, for and foreach loops Loops in PHP $count = 1; while ($count <= 10) { echo " $count "; echo " $count "; $count++; $count++;} $i = 10; do { echo $i. " \n"; echo $i. " \n"; $i--; $i--; } while ($i > 0); for ($i=0; $i<9; $i++) { echo " $i "; echo " $i ";} $nums = array(1, 2, 3); foreach ($nums as $x) echo $x. " "; echo $x. " ";

10  Write a PHP script to print the numbers from 1 to 20  Print the numbers in a list …  Print odd lines in blue, even lines in red Problem: Numbers 1 to 20 <ul> …</ul>

11 Solution: Numbers 1 to 20 <ul> <?php <?php for ($i = 1; $i <= 20; $i++) { for ($i = 1; $i <= 20; $i++) { if ($i % 2 == 0) if ($i % 2 == 0) $color = 'green'; $color = 'green'; else $color ='blue'; else $color ='blue'; echo "\t $i \n"; echo "\t $i \n"; } ?> } ?></ul> Check your solution here:

12  Write a PHP script to print a color palette like shown below: Problem: Color Palette rgb(0, 0, 0) rgb(0, 0, 0) rgb(0, 0, 51) rgb(0, 0, 51) … rgb(0, 0, 255) rgb(0, 0, 255) rgb(0, 51, 0) rgb(0, 51, 0) rgb(0, 51, 51) rgb(0, 51, 51) rgb(0, 51, 102) rgb(0, 51, 102) … rgb(0, 255, 255) rgb(0, 255, 255) rgb(51, 0, 0) rgb(51, 0, 0) … rgb(255, 255, 255) rgb(255, 255, 255)

13 Problem: Color Palette div { … } div { … } <?php for ($red = 0; $red <= 255; $red += 51) for ($green = 0; $green <= 255; $green += 51) for ($green = 0; $green <= 255; $green += 51) for ($blue = 0; $blue <= 255; $blue += 51) { for ($blue = 0; $blue <= 255; $blue += 51) { $color = "rgb($red, $green, $blue)"; $color = "rgb($red, $green, $blue)"; echo " $color \n"; echo " $color \n"; }?> Check your solution here:

14  HTML forms submit data to some URL Submitting HTML Forms <form> Name: Name: </form> hello-person.php hello-person.php?person=some_value

15 HTML Forms and PHP: Hello, Person! <?php if (isset($_GET['person'])) { if (isset($_GET['person'])) { $person = htmlspecialchars($_GET['person']); $person = htmlspecialchars($_GET['person']); echo "Hello, $person!"; echo "Hello, $person!"; } else { } else {?> Name: Name: Check your solution here: If the ' person ' HTTP GET parameter exists, print a greeting Otherwise, show a HTML form to enter a person

16  Write a PHP script to dump the content of the HTTP GET request parameters using var_dump(…) Problem: Dump a HTTP GET Request

17 Solution: Dump a HTTP GET Request <form> Name: Name: Age: Age: Town: Town: Sofia Sofia Varna Varna Plodvid Plodvid </form> All parameters will be passed as string values in $_GET[] array Check your solution here: Dump the $_GET[] array

18  Write a PHP script to sum two numbers  The script should display a HTML form to enter the numbers  If the numbers are passed as parameters, display their sum Problem: Sum Two Numbers

19 Solution: Sum Two Numbers <?php if (isset($_GET['num1']) && isset($_GET['num2'])) { $num1 = intval($_GET['num1']); $num1 = intval($_GET['num1']); $num2 = intval($_GET['num2']); $num2 = intval($_GET['num2']); $sum = $num1 + $num2; $sum = $num1 + $num2; echo "$num1 + $num2 = $sum"; echo "$num1 + $num2 = $sum"; } ?> <form> First Number: First Number: Second Number: Second Number: </form> Check your solution here: Sum the ' num1 ' and ' num2 ' values if exist Show a HTML form to submit num1 and num2

20  PHP is a server-side scripting language  Variables are prefixed by $, not declared  PHP supports classical if - else statements  PHP supports classical loop structures:  while, do - while, for, foreach  HTML forms send data as HTTP GET request  Access HTTP GET parameters from PHP using $_GET['param_name'] Summary

? ? ? ? ? ? ? ? ? First Steps in PHP

License  This course (slides, examples, demos, videos, homework, etc.) is licensed under the "Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International" licenseCreative Commons Attribution- NonCommercial-ShareAlike 4.0 International 22

Free Software University  Software University Foundation – softuni.orgsoftuni.org  Software University – High-Quality Education, Profession and Job for Software Developers  softuni.bg softuni.bg  Software Facebook  facebook.com/SoftwareUniversity facebook.com/SoftwareUniversity  Software YouTube  youtube.com/SoftwareUniversity youtube.com/SoftwareUniversity  Software University Forums – forum.softuni.bgforum.softuni.bg