SlideShare ist ein Scribd-Unternehmen logo
1 von 30
Downloaden Sie, um offline zu lesen
hasen@microcis.net July 03, 2013Hassen poreya
Trainer, Cresco Solution
Afghanistan Workforce
Development Program
PHP
Hypertext Pre-Processor
PHP
 PHP is a recursive acronym that stands for:
 PHP: Hypertext Preprocessor
 Hypertext :
 PHP is used to generate HTML pages.
 Preprocessor:
 The PHP code is processed before delivering HTML
content to the user.
PHP Tags
 Short tags
<?
?>
 Standard tags
<?php
?>
 XML compatible tags
<SCRIPT LANGUAGE="php">
</SCRIPT>
PHP Comments
 Single line comments
//this is a comment
#this is also a comment
 Multiple line comments
/*this is
a multiple line
comment
*/
A Simple PHP code
<html>
<head>
<title>My First PHP Script</title>
</head>
<body>
<?php
echo “Hello World!”;
?>
</body>
</html>
Language Basics – Semicolons
 Semicolons are used to separate different
statements.
<?php
echo “Hello World!”;
echo “Hi”;
?>
 Optional semicolons are coming after } but it’s
required to put a semicolon before }
if($day==“Monday”){
echo “Today is:”$day; //required semicolons here
}; //optional semicolons here
Language Basics – Variables Name
 Variables in PHP starts with $
 Case sensitive
$user_name and $User_Name (Different!!!)
 Valid variable names
$name
$day_of_month
$LastName
$_password
 Invalid variable names
$user name
$|
$5and10
Language Basics – Conventions
 Case sensitive
 Function names
 Class names
 Keywords
 You can not name your variables, functions, classes,
constants the same as a keyword.
 Constants -- Unchangeable value
 Does not start with $
 Using define()you can have a constant.
define(CONST', “A constant!");
echo CONST;
Data Types
 Scalar (Single value)
 Integers
 Floating-point numbers
 Boolean
 Strings
 Compound (Collections)
 Arrays
 Objects
 Special types
 Resource
 NULL
Integers
 Range [-2,147,483,648 to 2,147,483,647]
 Decimal
e.g. 2008
-123
 Octal numbers: a leading 0 and a sequence of digits
0-7
e.g. +0123
 Hexadecimal numbers: begin with 0x, followed by a
sequence of digits (0-9) or letters (A-F).
e.g. 0xFF
0x10
Floating-point Numbers
 Point (Decimal-point, floating-point)
 15 digits of accuracy
e.g.
0.61829384258
12.5
Testing a Data type
 is_int() or is_integer()
 Test, whether a value is an integer.
 is_float() or is_real()
 Test, whether a value is floating-point number.
 Return 1 if true, and 0 if false
<?php
$num=15;
$num2=4.5;
echo “$num is integer?”.is_int($num);
echo “<br> $num is float?”.is_float($num);
?>
Strings
 Strings are collections of textual data.
 e.g, “Microcis Software Solutions” or “Hello World!”
 Double quote VS single quote
 Double quotes expand the variables.
 Single quotes does not.
<?php
$a=“microcis”;
$b=„software‟;
$single=„single quote: $a‟;
double=“double quote: $b”
echo $single.“<br>”;
echo $double.“<br>”;
?>
NULL
 The special NULL value represents that a variable
has no value!
<?php
$var=NULL;
echo “$var is Null?”.is_null($var);
?>
 Use is_null() function whether a variable is
NULL.
Boolean
 A Boolean can be either TRUE or FALSE.
 The following values are considered FALSE
 The boolean(FALSE);
 The integer 0
 The float 0.0
 The empty string or string “0”
 The special type NULL
 An array with no elements
 An object with no value or functions
Boolean
 Every other value is considered as TRUE.
 -1 is considered TRUE, like any other non-zero number.
 Use is_bool() function to test whether a value
return true or false.
 Note: “something” is a string, not boolean; but it is
considered as boolean true.
Arrays
Arrays
 Array is series of objects which all have the same size
and type.
 Each object in an array is called an array element.
 A group of values
<?php
$city[0]=“Herat”;
$city[1]=“Kabul”;
$city[2]=“Mazar”;
?>
 You can also create an array using array()
$color=array(“Red”, “Green”, “Blue”);
print “$city[0] is $color[1]”;
Types of Arrays
 Associative arrays
 Numeric arrays
 Multidimensional arrays
Numeric Arrays
 A numeric array stores each element with a
numeric ID key.
$names = array(“Ahmad",“Mahmood",“Bob");
 In this example the ID key is automatically
assigned.
Associative Arrays
 With Associative arrays we can use strings as keys
and assign values to them.
$ages = array(“Ahmad"=>32, “Mahmood"=>30,
“Bob"=>34);
print_r($ages);
Multidimensional Arrays
 Each element in the main array can be an array.
And each element in the sub-array can also be an
array, and so on.
$countries = array(
“Afghanistan"=>array(“Herat",
“Kabul", “Mazar"), “Iran"=>array (
“Tehran" ), “Pakistan"=>array (
“Islamabad", “Peshavor", “Kerachi"
) );
Array Functions
print_r() function
 You can see the structure and values of any array
by using print_r() function.
print_r($fruit_basket);
 Output:
Array
(
[red] => apple
[orange] => orange
[yellow] => banana
[green] => pear
)
array_rand() function
 Returns a random key from an array, or it returns an
array of random keys.
 If you specify that, the function should return more
than one key.
array_rand(array,number);
<?php
$name=array("a"=>“Ahmad","b"=>“Bah
ram",“s"=>“Sina");
print_r(array_rand($name,1));
?>
 The output of the code above could be: b
Shuffle() function
 The shuffle() function randomizes the order
of the elements in the array.
shuffle(array);
<?php
$colors = array(“r" => “red", "b"
=> “blue", “g" => “green");
shuffle($colors);
print_r($colors);
?>
Output: Array ( [0] => blue [1] => green [2] => red )
str_split() function
 Splits a string into an array.
str_split(string,length)
 Parameters
 String: Specifies the string to split
 Length: Optional and specifies the length of each array
element. Default is 1
<?php
print_r(str_split("Hello"));
?>
str_split() function
 The output of the code above will be:
Array
(
[0] => H
[1] => e
[2] => l
[3] => l
[4] => o
)
Let’s codesomething
hasen@microcis.net July 03, 2013Hassen poreya
Trainer, Cresco Solution
Any Questions!

Weitere ähnliche Inhalte

Was ist angesagt?

PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisIan Macali
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requirePHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requireTheCreativedev Blog
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & ArraysHenry Osborne
 
Learn PHP Basics
Learn PHP Basics Learn PHP Basics
Learn PHP Basics McSoftsis
 
Class 8 - Database Programming
Class 8 - Database ProgrammingClass 8 - Database Programming
Class 8 - Database ProgrammingAhmed Swilam
 
Introduction to PHP Lecture 1
Introduction to PHP Lecture 1Introduction to PHP Lecture 1
Introduction to PHP Lecture 1Ajay Khatri
 
Dev traning 2016 basics of PHP
Dev traning 2016   basics of PHPDev traning 2016   basics of PHP
Dev traning 2016 basics of PHPSacheen Dhanjie
 
Basics of Java Script (JS)
Basics of Java Script (JS)Basics of Java Script (JS)
Basics of Java Script (JS)Ajay Khatri
 
Php using variables-operators
Php using variables-operatorsPhp using variables-operators
Php using variables-operatorsKhem Puthea
 
Chap1introppt2php(finally done)
Chap1introppt2php(finally done)Chap1introppt2php(finally done)
Chap1introppt2php(finally done)monikadeshmane
 
Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9isadorta
 

Was ist angesagt? (20)

PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requirePHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and require
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & Arrays
 
Learn PHP Basics
Learn PHP Basics Learn PHP Basics
Learn PHP Basics
 
php basics
php basicsphp basics
php basics
 
Class 8 - Database Programming
Class 8 - Database ProgrammingClass 8 - Database Programming
Class 8 - Database Programming
 
Introduction to PHP Lecture 1
Introduction to PHP Lecture 1Introduction to PHP Lecture 1
Introduction to PHP Lecture 1
 
Dev traning 2016 basics of PHP
Dev traning 2016   basics of PHPDev traning 2016   basics of PHP
Dev traning 2016 basics of PHP
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
Basics of Java Script (JS)
Basics of Java Script (JS)Basics of Java Script (JS)
Basics of Java Script (JS)
 
PHP MySQL
PHP MySQLPHP MySQL
PHP MySQL
 
Php using variables-operators
Php using variables-operatorsPhp using variables-operators
Php using variables-operators
 
Chap1introppt2php(finally done)
Chap1introppt2php(finally done)Chap1introppt2php(finally done)
Chap1introppt2php(finally done)
 
Php variables (english)
Php variables (english)Php variables (english)
Php variables (english)
 
Php introduction
Php introductionPhp introduction
Php introduction
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
Php Security
Php SecurityPhp Security
Php Security
 
Php & my sql
Php & my sqlPhp & my sql
Php & my sql
 
Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9
 

Andere mochten auch

Web app development_html_css_03
Web app development_html_css_03Web app development_html_css_03
Web app development_html_css_03Hassen Poreya
 
Web app development_php_07
Web app development_php_07Web app development_php_07
Web app development_php_07Hassen Poreya
 
Web app development_database_design_10
Web app development_database_design_10Web app development_database_design_10
Web app development_database_design_10Hassen Poreya
 
Web app development_php_05
Web app development_php_05Web app development_php_05
Web app development_php_05Hassen Poreya
 
Web app development_my_sql_08
Web app development_my_sql_08Web app development_my_sql_08
Web app development_my_sql_08Hassen Poreya
 
Web app development_crud_13
Web app development_crud_13Web app development_crud_13
Web app development_crud_13Hassen Poreya
 
Web app development_my_sql_09
Web app development_my_sql_09Web app development_my_sql_09
Web app development_my_sql_09Hassen Poreya
 
Web app development_database_design_11
Web app development_database_design_11Web app development_database_design_11
Web app development_database_design_11Hassen Poreya
 
Web app development_database_design_er-mapping_12
Web app development_database_design_er-mapping_12Web app development_database_design_er-mapping_12
Web app development_database_design_er-mapping_12Hassen Poreya
 
Learn to Code with JavaScript - Choose Your Own Adventures
Learn to Code with JavaScript - Choose Your Own AdventuresLearn to Code with JavaScript - Choose Your Own Adventures
Learn to Code with JavaScript - Choose Your Own AdventuresTessa Mero
 
Web app development_php_06
Web app development_php_06Web app development_php_06
Web app development_php_06Hassen Poreya
 
Web app development_cookies_sessions_14
Web app development_cookies_sessions_14Web app development_cookies_sessions_14
Web app development_cookies_sessions_14Hassen Poreya
 
Web app development_html_01
Web app development_html_01Web app development_html_01
Web app development_html_01Hassen Poreya
 
Web app development_html_02
Web app development_html_02Web app development_html_02
Web app development_html_02Hassen Poreya
 

Andere mochten auch (15)

Web app development_html_css_03
Web app development_html_css_03Web app development_html_css_03
Web app development_html_css_03
 
Web app development_php_07
Web app development_php_07Web app development_php_07
Web app development_php_07
 
Web app development_database_design_10
Web app development_database_design_10Web app development_database_design_10
Web app development_database_design_10
 
Web app development_php_05
Web app development_php_05Web app development_php_05
Web app development_php_05
 
Web app development_my_sql_08
Web app development_my_sql_08Web app development_my_sql_08
Web app development_my_sql_08
 
Web app development_crud_13
Web app development_crud_13Web app development_crud_13
Web app development_crud_13
 
CodeIgniter Practice
CodeIgniter PracticeCodeIgniter Practice
CodeIgniter Practice
 
Web app development_my_sql_09
Web app development_my_sql_09Web app development_my_sql_09
Web app development_my_sql_09
 
Web app development_database_design_11
Web app development_database_design_11Web app development_database_design_11
Web app development_database_design_11
 
Web app development_database_design_er-mapping_12
Web app development_database_design_er-mapping_12Web app development_database_design_er-mapping_12
Web app development_database_design_er-mapping_12
 
Learn to Code with JavaScript - Choose Your Own Adventures
Learn to Code with JavaScript - Choose Your Own AdventuresLearn to Code with JavaScript - Choose Your Own Adventures
Learn to Code with JavaScript - Choose Your Own Adventures
 
Web app development_php_06
Web app development_php_06Web app development_php_06
Web app development_php_06
 
Web app development_cookies_sessions_14
Web app development_cookies_sessions_14Web app development_cookies_sessions_14
Web app development_cookies_sessions_14
 
Web app development_html_01
Web app development_html_01Web app development_html_01
Web app development_html_01
 
Web app development_html_02
Web app development_html_02Web app development_html_02
Web app development_html_02
 

Ähnlich wie Web app development_php_04

Ähnlich wie Web app development_php_04 (20)

PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
 
FYBSC IT Web Programming Unit IV PHP and MySQL
FYBSC IT Web Programming Unit IV  PHP and MySQLFYBSC IT Web Programming Unit IV  PHP and MySQL
FYBSC IT Web Programming Unit IV PHP and MySQL
 
Training on php by cyber security infotech (csi)
Training on  php by cyber security infotech (csi)Training on  php by cyber security infotech (csi)
Training on php by cyber security infotech (csi)
 
PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array. PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array.
 
php&mysql with Ethical Hacking
php&mysql with Ethical Hackingphp&mysql with Ethical Hacking
php&mysql with Ethical Hacking
 
unit 1.pptx
unit 1.pptxunit 1.pptx
unit 1.pptx
 
Php
PhpPhp
Php
 
Php Lecture Notes
Php Lecture NotesPhp Lecture Notes
Php Lecture Notes
 
Php by shivitomer
Php by shivitomerPhp by shivitomer
Php by shivitomer
 
Php 101 by David Menendez
Php 101 by David MenendezPhp 101 by David Menendez
Php 101 by David Menendez
 
PHP
PHPPHP
PHP
 
PHP - Web Development
PHP - Web DevelopmentPHP - Web Development
PHP - Web Development
 
PHP and MySQL with snapshots
 PHP and MySQL with snapshots PHP and MySQL with snapshots
PHP and MySQL with snapshots
 
lab4_php
lab4_phplab4_php
lab4_php
 
lab4_php
lab4_phplab4_php
lab4_php
 
Php basic for vit university
Php basic for vit universityPhp basic for vit university
Php basic for vit university
 
Php
PhpPhp
Php
 
Web 8 | Introduction to PHP
Web 8 | Introduction to PHPWeb 8 | Introduction to PHP
Web 8 | Introduction to PHP
 
Php
PhpPhp
Php
 
Php basics
Php basicsPhp basics
Php basics
 

Kürzlich hochgeladen

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 

Kürzlich hochgeladen (20)

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 

Web app development_php_04

  • 1. hasen@microcis.net July 03, 2013Hassen poreya Trainer, Cresco Solution Afghanistan Workforce Development Program PHP Hypertext Pre-Processor
  • 2. PHP  PHP is a recursive acronym that stands for:  PHP: Hypertext Preprocessor  Hypertext :  PHP is used to generate HTML pages.  Preprocessor:  The PHP code is processed before delivering HTML content to the user.
  • 3. PHP Tags  Short tags <? ?>  Standard tags <?php ?>  XML compatible tags <SCRIPT LANGUAGE="php"> </SCRIPT>
  • 4. PHP Comments  Single line comments //this is a comment #this is also a comment  Multiple line comments /*this is a multiple line comment */
  • 5. A Simple PHP code <html> <head> <title>My First PHP Script</title> </head> <body> <?php echo “Hello World!”; ?> </body> </html>
  • 6. Language Basics – Semicolons  Semicolons are used to separate different statements. <?php echo “Hello World!”; echo “Hi”; ?>  Optional semicolons are coming after } but it’s required to put a semicolon before } if($day==“Monday”){ echo “Today is:”$day; //required semicolons here }; //optional semicolons here
  • 7. Language Basics – Variables Name  Variables in PHP starts with $  Case sensitive $user_name and $User_Name (Different!!!)  Valid variable names $name $day_of_month $LastName $_password  Invalid variable names $user name $| $5and10
  • 8. Language Basics – Conventions  Case sensitive  Function names  Class names  Keywords  You can not name your variables, functions, classes, constants the same as a keyword.  Constants -- Unchangeable value  Does not start with $  Using define()you can have a constant. define(CONST', “A constant!"); echo CONST;
  • 9. Data Types  Scalar (Single value)  Integers  Floating-point numbers  Boolean  Strings  Compound (Collections)  Arrays  Objects  Special types  Resource  NULL
  • 10. Integers  Range [-2,147,483,648 to 2,147,483,647]  Decimal e.g. 2008 -123  Octal numbers: a leading 0 and a sequence of digits 0-7 e.g. +0123  Hexadecimal numbers: begin with 0x, followed by a sequence of digits (0-9) or letters (A-F). e.g. 0xFF 0x10
  • 11. Floating-point Numbers  Point (Decimal-point, floating-point)  15 digits of accuracy e.g. 0.61829384258 12.5
  • 12. Testing a Data type  is_int() or is_integer()  Test, whether a value is an integer.  is_float() or is_real()  Test, whether a value is floating-point number.  Return 1 if true, and 0 if false <?php $num=15; $num2=4.5; echo “$num is integer?”.is_int($num); echo “<br> $num is float?”.is_float($num); ?>
  • 13. Strings  Strings are collections of textual data.  e.g, “Microcis Software Solutions” or “Hello World!”  Double quote VS single quote  Double quotes expand the variables.  Single quotes does not. <?php $a=“microcis”; $b=„software‟; $single=„single quote: $a‟; double=“double quote: $b” echo $single.“<br>”; echo $double.“<br>”; ?>
  • 14. NULL  The special NULL value represents that a variable has no value! <?php $var=NULL; echo “$var is Null?”.is_null($var); ?>  Use is_null() function whether a variable is NULL.
  • 15. Boolean  A Boolean can be either TRUE or FALSE.  The following values are considered FALSE  The boolean(FALSE);  The integer 0  The float 0.0  The empty string or string “0”  The special type NULL  An array with no elements  An object with no value or functions
  • 16. Boolean  Every other value is considered as TRUE.  -1 is considered TRUE, like any other non-zero number.  Use is_bool() function to test whether a value return true or false.  Note: “something” is a string, not boolean; but it is considered as boolean true.
  • 18. Arrays  Array is series of objects which all have the same size and type.  Each object in an array is called an array element.  A group of values <?php $city[0]=“Herat”; $city[1]=“Kabul”; $city[2]=“Mazar”; ?>  You can also create an array using array() $color=array(“Red”, “Green”, “Blue”); print “$city[0] is $color[1]”;
  • 19. Types of Arrays  Associative arrays  Numeric arrays  Multidimensional arrays
  • 20. Numeric Arrays  A numeric array stores each element with a numeric ID key. $names = array(“Ahmad",“Mahmood",“Bob");  In this example the ID key is automatically assigned.
  • 21. Associative Arrays  With Associative arrays we can use strings as keys and assign values to them. $ages = array(“Ahmad"=>32, “Mahmood"=>30, “Bob"=>34); print_r($ages);
  • 22. Multidimensional Arrays  Each element in the main array can be an array. And each element in the sub-array can also be an array, and so on. $countries = array( “Afghanistan"=>array(“Herat", “Kabul", “Mazar"), “Iran"=>array ( “Tehran" ), “Pakistan"=>array ( “Islamabad", “Peshavor", “Kerachi" ) );
  • 24. print_r() function  You can see the structure and values of any array by using print_r() function. print_r($fruit_basket);  Output: Array ( [red] => apple [orange] => orange [yellow] => banana [green] => pear )
  • 25. array_rand() function  Returns a random key from an array, or it returns an array of random keys.  If you specify that, the function should return more than one key. array_rand(array,number); <?php $name=array("a"=>“Ahmad","b"=>“Bah ram",“s"=>“Sina"); print_r(array_rand($name,1)); ?>  The output of the code above could be: b
  • 26. Shuffle() function  The shuffle() function randomizes the order of the elements in the array. shuffle(array); <?php $colors = array(“r" => “red", "b" => “blue", “g" => “green"); shuffle($colors); print_r($colors); ?> Output: Array ( [0] => blue [1] => green [2] => red )
  • 27. str_split() function  Splits a string into an array. str_split(string,length)  Parameters  String: Specifies the string to split  Length: Optional and specifies the length of each array element. Default is 1 <?php print_r(str_split("Hello")); ?>
  • 28. str_split() function  The output of the code above will be: Array ( [0] => H [1] => e [2] => l [3] => l [4] => o )
  • 30. hasen@microcis.net July 03, 2013Hassen poreya Trainer, Cresco Solution Any Questions!