Thursday 13 September 2012

Intro PHP Lesson 1

0 comments


Basics for beginners

Programming language PHP for web development


Php: Hypertext Preprocessor

  • Php is a server-side scripting language
  • Open source
  • Easy to use
  • Community support
  • Supports databases such as MySQL

What do you need to get started?

  • Operating system
  • Web server 
  • Php interpreter
  • Database engine such as MySQL
Syntax
  • Php always starts with <?php and ends with ?>
  • Php file must have a .php extension
  • Php code is inside the HTML tags
Example1: Displaying text in your browser 

<html>
<body>

<?php echo "Lets learn php"; ?>

</body>
</html>

TRY IT!
Download Example
https://docs.google.com/file/d/0B7SlVynBEEAbZ3dzd2FjQ0R1Y00/edit


Semicolon:
  • Each php line must end with a semicolon
  • It is a separator used to identify end of a php statement
Echo:
  • Used to output text

How to add comments?
// Single line comment
/* text here */ Multi-line comment
<!--  text here    --> Html


Example
<html>
<body>

<?php

// this is a single line comment

/*this
is a multi-line
comment */

?>

</body>
</html>

White Space
  • White does not matter in coding, it is totally ignored.
  • It is okay to have one line of php code, then 15 lines of blank space before the next php line of code.
  • Example:
<?php

echo "hallo";

echo "world";




?>


Escaping special characters
  • NB to use double quotations
\n
A line feed character
\t
Tab
\r
Carriage return
\”
Double quotation
\’
Single quoatation
To be printed “as is

Example 2
<?php echo  “You said \”Hallo\””;?>

Example 3
Use <pre> tags to display a linefeed
<pre>
<?php echo “Welcome\nto\nPHP”;?>
</pre>



 

Janine Keyser J9 Photography