Friendly PHP Course – Part #1 Writing PHP Statements and Variables


Deprecated: Function create_function() is deprecated in /home/vhosts/poweredbygnulinux.com/wp-content/plugins/codecolorer/lib/geshi.php on line 4698

phplogo

Programs perform the tasks:  create and display Web pages,accept and process information from users, store information in the database, get information out of the database

PHP

Is a scripting language designed for use on the Web

Adding a PHP section to an HTML page

HTML forms allow users to type information that the Web page is designed to collect however, you can not access thatinformation without using a language other than HTML.
PHP processes this information and allows other interactive tasks as well

HTML Tags

They are used to make PHP language statements part of HTML. The file is named with a .php extension

PHP language statements

PHP processes all statements between the two PHP tags.

 <?php  ?>

The browser doesn’t see the PHP section only its output
Example

 <?php

?>

<head>

<title>hello world program</title>

</head>

<body>

<?php echo "<Hello World!</p>"

?>

</body>

<html>

The echo statement is a PHP statement that simply outputs the text that is included between the double quotes.
When the PHP section is processed, it is replaced with the output

<p>Hello World!</p>

 

Writing PHP Statements
PHP statements end with a semicolon (;)
PHP does not notice white space or the ends of lines.PHP continues reading until it encounters a semicolon or the PHP closing tag

Blocks
Blocks are a groups of statements are combined into a block. Enclosed by curly braces, { and }

A common use is as a conditional block statements executed only when certain conditions are true. Blocks are complex statements.
PHP reads the entire complex statement, not stopping at the first semicolon that it encounters. You should indent the statements in a block so that people reading the script .PHP doesn’t care whether the statement keywords are in uppercase or lowercase

Variables

Variables are containers used to hold information . A variable has a name, and information is stored in the variable .fter information is stored in a variable, it can be used later in the program.
Commonly a variable hold the information that a user types into a form.

    Naming a variable

  • All variable names have a dollar sign ($) in front of them.
  • Variable names must begin with a letter or an underscore.
  • They cannot begin with a number.
  • Variable names can include letters, numbers, and underscores only.
  • Uppercase and lowercase letters are not the same.
  • Use names that make it clear what information is in the variable

Creating and assigning values

Variables can hold either numbers or strings of characters

using a single equal sign (=)

$age = 12;

Character string is enclosed in quotes, but the numbers are not

Using a Variable

This command is used to display a variable value:

 echo $age;

the output is 12

Whenever you put information into a variable that did not exist before, you create that variable

$firstname = "Lucas";

Remove information from a variable

$age = "";
unset($age);

The variable $age no longer exists
A variable keeps its information for the entire program

 

Finally a summary in a mindmap

pdficon

Download PDF Mindmap

application-arrow-right-icon

Next Chapter

You may also like...