php: PHP Hypertext preprocessor
Its a server-side scripting language (data collect, save, add, delete, modify, encrypt). It is much like HTML (HTML-embedded) and syntax is C-like. Its case-sensitive
Web development and database (MYSQL, Oracle, Microsoft SQL Server) can interact through php
First released in 1996
It supports protocols as IMAP, POP3, LDAP
Characteristics of php: simple, flexible, forgiving, secure, efficient, fast, compatible
Componnets needed for php web page operation: web server, database, php parser
Script extension is .php
php configuation file is php.ini
php tag style <?php...?>
Comments: # for single line
/* for multi-line*/
Executing script from command prompt: php script.php
php constants: _LINE_, _FILE_,_FUNCTION_,_CLASS_,_METHOD_
-------------------------
#Hello script
<html>
<head>
<title>Online PHP Script Execution</title>
</head>
<body>
<?php
echo "<h1>Hello</h1>";
?>
</body>
</html>
Hello
-------------------------
#Case sensitive nature of php
<html>
<body>
<?php
$age = 21;
print("I am $age<br>");
print("I am $Age<br>");
?>
</body>
</html>
I am 21
I am
-------------------------
#If statement, condition check, braces to make blocks
<html>
<head>
<title>Online PHP Script Execution</title>
</head>
<body>
<?php
if (4 == 2 + 2)
print("TRUE<br>");
if (5 == 2 + 2){
print("FALSE");
};
?>
</body>
</html>
Its a server-side scripting language (data collect, save, add, delete, modify, encrypt). It is much like HTML (HTML-embedded) and syntax is C-like. Its case-sensitive
Web development and database (MYSQL, Oracle, Microsoft SQL Server) can interact through php
First released in 1996
It supports protocols as IMAP, POP3, LDAP
Characteristics of php: simple, flexible, forgiving, secure, efficient, fast, compatible
Componnets needed for php web page operation: web server, database, php parser
Script extension is .php
php configuation file is php.ini
php tag style <?php...?>
Comments: # for single line
/* for multi-line*/
Executing script from command prompt: php script.php
php constants: _LINE_, _FILE_,_FUNCTION_,_CLASS_,_METHOD_
-------------------------
#Hello script
<html>
<head>
<title>Online PHP Script Execution</title>
</head>
<body>
<?php
echo "<h1>Hello</h1>";
?>
</body>
</html>
Hello
-------------------------
#Case sensitive nature of php
<html>
<body>
<?php
$age = 21;
print("I am $age<br>");
print("I am $Age<br>");
?>
</body>
</html>
I am 21
I am
-------------------------
#If statement, condition check, braces to make blocks
<html>
<head>
<title>Online PHP Script Execution</title>
</head>
<body>
<?php
if (4 == 2 + 2)
print("TRUE<br>");
if (5 == 2 + 2){
print("FALSE");
};
?>
</body>
</html>
TRUE
-------------------------
Variables (Integers, double, boolean)
Integers
<?php
$a = 7;
$b = 3;
$sum = $a + $b;
$minus = $a - $b;
print ("$a + $b = $sum <br>");
print ("$a - $b = $minus <br>");
?>
7 + 3 = 10
7 - 3 = 4
7 - 3 = 4
-----------
Doubles
<?php
$a = 2.7;
$b = 5.8;
$total = $a + $b;
print ("$a + $b = $total <br>");
?>
2.7 + 5.8 = 8.5
-----------
Boolean
<?php
if (TRUE)
print("Yes<br>");
else
print("No <br>");
?>
True
-----------
Assigning multiple lines to single variable
<?php
$abc =<<<_XML_
<abc>
<description>Winter night.</description>
<description>Its raining.</description>
</abc>
_XML_;
echo <<<END
Mid December.
END;
print $abc;
?>
Mid December. Winter night. Its raining.
-----------
<?php
define("MINSIZE", 24);
#echo MINSIZE;
echo constant("MINSIZE");
?>
24
-----------
If......else
<?php
$d=date("D");
if ($d=="Sun")
echo "Play";
else
echo "Study";
?>
Study
-----------
elseif (When at least one condition is true)
<?php
$d=date("D");
if ($d=="Sat")
echo "Hike";
elseif ($d=="Sun")
echo "Play";
else
echo "Study";
?>
Study
-----------
switch (evaluates, matches, if found executed, otherwise executes a specified default code)
<?php
$d=date("D");
switch ($d)
{
case "Mon":
echo "Study";
break;
case "Tue":
echo "Study";
break;
case "Wed":
echo "Study";
break;
default:
echo "Relax on weekend.";
}
?>
Study
-----------
for loop (specified number of time)
while (as long as condition is true)
do....while
foreach (loops for each element)
-----------
No comments:
Post a Comment