PHP Intro
PHP Intro
<?php
echo "Hello World!";
?>
</body>
</html>
Basic PHP Syntax
<?php
// PHP code goes here
?>
Comments in PHP
<?php
// This is a single-line comment
/*
This is a multiple-lines comment block
that spans over multiple
lines
*/
// You can also use comments to leave out parts of a code line
$x = 5 /* + 15 */ + 5;
echo $x;
?>
</body>
</html>
PHP Case Sensitivity
<?php
ECHO "Hello World!<br>";
echo "Hello World!<br>";
EcHo "Hello World!<br>";
?>
</body>
</html>
<?php
$color = "red";
echo "My car is " . $color . "<br>";
echo "My house is " . $COLOR
. "<br>";
echo "My boat is " . $coLOR . "<br>";
?>
</body>
</html>
PHP Variables
- Variables are "containers" for storing
information.
<?php
$txt = “Jh Cerilles State College";
echo "I love $txt!";
?>
PHP Variables Scope
function myTest() {
// using x inside this
function will generate an
error
echo "<p>Variable x
inside function is: $x</p>";
}
myTest();
function myTest() {
global $x, $y;
$y = $x + $y;
}
myTest();
echo $y; // outputs 15
?>
<?php
$x = 5;
$y = 10;
function myTest() {
$GLOBALS['y'] = $GLOBALS['x']
+ $GLOBALS['y'];
}
myTest();
echo $y; // outputs 15
?>
PHP The static Keyword
myTest();
Echo “<br>”;
myTest();
Echo “<br>”;
myTest();
?>
Questions?
1.What is the missing part of the code
below to out “Hello World”
_________
echo “Hello World”
2. What is the correct opening tag and
closing tag for PHP script.
<?php
______________
?>
______________
3. Single-line comments in PHP can be
written using different prefixes, write on of
them.
// or #
4. What is the correct characters to write
a multi-line comment?
;
In a yellow pad paper, write the code of the
ff;