Friday, 13 June 2014

Control Structures Introduction in PHP (IF)

Any PHP script is built out of a series of statements. A statement can be an assignment, a function call, a loop, a conditional statement or even a statement that does nothing (an empty statement). Statements usually end with a semicolon. The various statement types are described in this chapter

if

<?phpif ($a $b) {
  echo 
"a is greater than b";
} else {
  echo 
"a is NOT greater than b";
}
?>

If expression evaluates to TRUE, PHP will execute statement, and if it evaluates to FALSE - it'll ignore it. More information about what values evaluate to FALSE can be found in the 'Converting to boolean' section.


Alternative syntax for control structures

<?php if ($a == 5): ?>A is equal to 5
<?php endif; ?>

Tuesday, 3 June 2014

Introduction to PHP

PHP: Hypertext Preprocessor, is a open source scripting language that is especially suited for web development and can be embedded into HTML. The PHP code is enclosed in special start and end <?php and ?> processing instructions .

PHP is executed on the server, generating HTML which is then sent to the client. The client would receive the results of running that script.

Example #1 An introductory example
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>Example</title>
    </head>
    <body>

        <?php
            
echo "Hi, I'm a PHP script!";
        
?>
    </body>
</html>