lecture – 2 php introductionvip.gatech.edu/wiki/images/8/8a/lec2011_2.pdf · php introduction...
TRANSCRIPT
LAMP is an acronym for a solution stack of free, open source software, originally coined from the first letters of Linux (operating system), Apache HTTP Server, MySQL (database software) and Perl/PHP/Python, principal components to build a viable general purpose web server.
Unix clone
Kernel of an Operating System
Different distributions: Debian, Mandrake, RedHat and many others Totally free, but not "free" as in "free beer”
Multi-user: Secure "by design“ Multi-platform: Runs on many different architectures: Intel, Motorola, Sparc, PowerPC A networking OS
Flexible, Easy to configure
Serves over 70% of all websites Robust, fast: It just works
Multiple serving architectures: the best for each platform
Many extensions
Very easy to setup and use
But still quite powerful
Robust and fast: It can easily outperform e.g. Oracle in simple tasks
Open Source, but also commercially backed Cross-platform
Web Scripting language by design
Extremely shallow learning curve
Powerful and flexible
Cross-platform
Easily extended
Yahoo! (Apache and PHP)
Military
Lufthansa
…. and many more
PHP is a server side language. PHP has an HTML-centric approach.
HTML :
<html>
Hello World
</html>
PHP:
<html>
<?php echo "Hello World" ?>
</html>
The 4 available tag styles
<html>
<body>
<? echo 'Short Tags - Most common' ?>
<?php echo 'Long Tags - Portable' ?>
<%= 'ASP Tags' %>
<script language="php">
echo 'Really Long Tags - rarely used';
</script>
</body>
</html>
<?php
$foo = 1;
$bar = "Testing";
$xyz = 3.14;
$foo = $foo + 1;
?>
<?php
$foo[1] = 1;
$foo[2] = 2;
$bar[1][2] = 3;
?>
<html>
<head>
<title>Example #1 TDavid's Very First PHP Script ever!</title>
</head>
<? print(Date("l F d, Y")); ?>
<body></body>
</html>
<?php
phpinfo();
foo();
$len = strlen($foo);
?>
<?php
// Show all information, defaults to INFO_ALL
phpinfo();
// Show just the module information.
phpinfo(8) //yields identical
results.phpinfo(INFO_MODULES);?>
<?php
while($foo)
{ ... }
?>
<?php
echo $foo;
printf(".2f",$price);?>
<? if(strstr($_SERVER['HTTP_USER_AGENT'],"MSIE")) { ?>
<b>
You are using Internet Explorer
</b>
<? } else { ?>
<b>You are not using Internet Explorer</b>
<? } ?>
<?php
echo $foo;
printf(".2f",$price);?>
Traditional
<form action="action.php" method="POST">
Your name:
<input type=text name=name>
<br>You age: <input type=text name=age><br>
<input type=submit></form>
PHP
Hi <?php echo $_POST['name']?>. You are
<?php echo $_POST['age']?> years old.
Number
<?php
$a = 1234;
$b = 0777;
$c = 0xff;
$d = 1.25;
echo "$a $b $c $d<br />\n";?>
Result: 1234 511 255 1.25
<?php
$name = 'Rasmus
$last'; // Single-quoted
$str = "Hi $name\n"; // Double-quoted echo $str;?>
Output Hi Rasmus $last
<?php
$greeting = true;
if($greeting)
{
echo "Hi Carl";
$greeting = false;
}?>
Output : Hi Carl
Don't have to declare types
Automatic conversion done
<?php echo 5 + "1.5" + "10e2";?>
Output : 1006.5
Questions?