Unit 1: Orientation and First Steps

4th semester

Unit 2 Unit 3 Unit 4 Unit 5 Unit 6 Unit 7 Unit 8 Unit 9 Unit 10
Definition :-

  • PHP stands for PHP: Hypertext Preprocessor .
  • PHP is a server-side scripting language, like ASP .
  • PHP scripts are executed on the server .
  • PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.)
  • PHP is an open source software .
  • PHP is free to download and use.

1.1 PHP’s Place in the Web World

This section explains how PHP fits into the interaction between a web browser and a web server.When you sit down at your computer and pull up a web page using a browser such as Internet Explorer or Mozilla, you
cause a little conversation to happen over the Internet between your computer and another computer. This conversation and  how it makes a web page appear on your screen is illustrated in Figure
Capture.JPG
Here’s what’s happening in the numbered steps of the diagram:
1. You type www.example.com/catalog.html into the location bar of Internet Explorer.
2. Internet Explorer sends a message over the Internet to the computer named www.example.com asking for the
/catalog.html page.
3. Apache, a program running on the www.example.com computer, gets the message and reads the catalog.html file
from the disk drive.
4. Apache sends the contents of the file back to your computer over the Internet as a response to Internet Explorer’s
request.
5. Internet Explorer displays the page on the screen, following the instructions of the HTML tags in the page.

1.2 What’s So Great About PHP? (see  course book for detial)

  • PHP Is Free (as in Money)
  • PHP Is Free (as in Speech)
  • PHP Is Cross-Platform

You can use PHP with a web server computer that runs Windows, Mac OS X, Linux, Solaris, and many other versions of Unix. Plus, if you switch web server operating systems, you generally don’t have to change any of your PHP programs. Just copy them from your Windows server to your Unix server, and they will still work.

  • PHP Is Widely Used
  • PHP Hides Its Complexity

1.3 PHP in Action

Ready for your first taste of PHP?
The PHP interpreter runs the commands  always starts with <?php and ends with ?>. A PHP scripting block can be placed anywhere in the document. A PHP file normally contains HTML tags, just like an HTML file, and some PHP scripting code.
Below, we have an example of a simple PHP script which sends the text “Hello World” to the browser:

<html>
<body>
<?php
echo "Hello World";
?>
</body>
</html>

1.4 Basic Rules of PHP Programs]

1.4.1 Start and End Tags

<?php as the PHP start tag and ?> as the PHP end tag. The PHP interpreter ignores anything outside of those tags. Text before the start tag or after the end tag is printed with no interference from the PHP interpreter.A PHP program can have multiple start and end tag pairs

1.4.2 Whitespace and Case-Sensitivity

PHP is insensitive of whitespace. This includes all types of spaces that are invisible on the screen including tabs, spaces, and carriage return. Even one space is equal to any numbers of spaces or carriage return. This means that PHP will ignore all the spaces or tabs in a single row or carriage return in multiple rows. Unless a semi-colon is encountered, PHP treats multiple lines as a single command.
PHP is case-sensitive. All the keywords, functions and class names in PHP (while, if, echo etc) are NOT case-sensitive except variables. Only variables with different cases are treated differently. Let’s look at this example:

1.4.3 Comments

A comment is something which is ignored and not read or executed by PHP engine or the language as part of a program and is written to make the code more readable and understandable.
PHP supports two types of comment:

  • Single Line Comment: As the name suggests these are single line or short relevant explanations that one can add in there code. To add this, we need to begin the line with (//) or (#).
    Example:<

    ?php
    // This is a single line comment
     // These cannot be extended to more lines
    echo "hello world!!!";
    # This is also a single line comment
    ?>

    Multi-line or Multiple line Comment: These are used to accomodate multiple lines with a single tag and can be extended to many lines as required by the user. To add this, we need to begin and end the line with (/*…*/)

<?php
/* This is a multi line comment  
   In PHP variables are written by adding a $ sign at the beginning.*/
  $geek = "hello world!";
echo $geek;
?>