29 Jan 2014

OPERATORS IN PHP :- Arithmetic Operator

PHP can perform simple Mathematical operations all the way to complex trigonometric equations.


















OPERATORS IN PHP :- Logical Operators

Logical operators are used when we want to combine operations and expressions into a set of logical comparisons. They are usually used in conjuction with "if and "else" statements to lay out the dynamic logic we need in many situations as we advance in our PHP development.

Name Usage Result
And $var1 && $var2 TRUE if both $var1 and $var2 are TRUE
And $var1 and $var2 TRUE if both $var1 and $var2 are TRUE
Or $var1 or $var2 TRUE if either $var1 or $var2 is TRUE
Or $var1 || $var2 TRUE if either $var1 or $var2 is TRUE
Xor $var1 xor $var2 TRUE if either $var1 or $var2 is TRUE, but not both
Is Not !$var1 TRUE if $var1 is not TRUE



example:-


28 Jan 2014

OPERATORS IN PHP :- Comparison Operators

PHP comparison operators allow you to compare two values against each other.The comparison is read from left to right by the PHP engine. Widely use in Conditional Logic and Control Structures.

  1. Equal    :- $var1 == $var2  Result :- TRUE if $var1 is equal to $var2.
  2. Identical    :- $var1 === $var2  Result :- TRUE if $var1 is equal to $var2, and they are of the same type
  3. Not Equal    :- $var1 != $var2 Result :- TRUE if $var1 is not equal to $var2
  4. Not Equal    :- $var1 < > $var2  Result :- TRUE if $var1 is not equal to $var2.
  5. Not Identical    :- $var1 !== $var2  Result :- TRUE if $var1 is not equal to $var2, or they are not the same type.
  6. Less Than    :- $var1 < $var2   Result :- TRUE if $var1 is strictly less than $var2.
  7. Greater Than    :- $var1 > $var2   Result :- TRUE if $var1 is strictly greater than $var2.
  8. Less Than or Equal to    :- $var1 <= $var2   Result :- TRUE if $var1 is less than or equal to $var2.
  9. Greater Than or Equal to    :- $var1 >= $var2   Result :- TRUE if $var1 is greater than or equal to $var2.
 example
 

OPERATORS IN PHP :- Concatenation

The concatenation operator ( . ) returns the combined value of its right and left values.
The variable's data type has an affect on the output.

example :-

















The concatenating assignment operator ( .= ), which appends the variable value on the right side to the variable on the left side. We use this method many times to compound and keep adding to one variable so it will retain its current value, and just append the new values onto the current value's tail end.

example :-

OPERATORS IN PHP :- Increment and Decrement operator

Incrementing and Decrementing operators are very widely used in most programming languages. They allow a PHP programmer to increment and decrement values as needed.
  1. Pre-Increment     ++$MyVariable  Result Increments $MyVariable by one.
  2. Post-Increment    $MyVariable++ Result Returns $MyVariable, then increments $myVar by one.
  3. Pre-Decrement    --$MyVariable  Result Decrements $MyVariable by one.
  4. Post-Decrement   $MyVariable-- Result Returns $MyVariable, then decrements $myVar by one.
example:-
 

OPERATORS IN PHP :- The Assignment operator


The Assignment operator is the most widely used in PHP.
We use it every time you create a variable.
The "="(equal to) sign is used, and what it does is it takes the expression from the right and places it into the operand on the left. It is simple.

example:-

20 Apr 2013

What is Variable in php ?

Variables are used to make processes we script out more dynamic. In the programming world the word variable means
"a symbolic name associated with a value and whose associated value may be changed". 

PHP sports a cool feature called automatic data typing. A PHP developer can claim variables and use them in most common situations without having to claim the data type that the variable is.

How to create variable
  1. PHP variables must made by placing a dollar sign [ $ ]  and then the name of the variable directly after it.
  2. Variable name must starts from character or underscore.
  3. Do not use a NUMBER to start a variable name.
example













Predefined Variables
There are a set of predefined variables in PHP that are always available for use in any script or scope in your applications. When data is created, sent, or stored using mechanisms that create superglobal variables, we can then access those variables site-wide or all throughout our scripts and scope. Predefined superglobals are available to all of your scripts that are part of a website or application you are creating.

The superglobal variables are:
$_GET Stores any variables created using the GET method
$_POST Stores any variables created using the POST method
$_REQUEST Stores any variables created through a user input script (it can access both POST or GET)
$_FILES Stores any file upload variables created through user input scripts
$_SESSION Stores any variables created through registering session variables
$_COOKIE Stores any variables created through setcookie
$GLOBALS Stores any variables that have been globally defined
$_SERVER Stores server information such as headers, file names, reference paths, and current page.
$_ENV Stores any variables associated with the server environment.

example
















Magic Constants (Predefined)


What is echo and print

print and echo are both used to output data to browser software or other technologies that intake external data. As you come to view different PHP scripts in your travels online you may notice some authors use echo and some use print. Let us discuss the difference.

echo() = is a language construct, so you are not required to use parentheses with it. If you ever need to pass more than one parameter to echo(), the parameters must not be enclosed within parentheses.

print() = behaves as a Function, but is not actually a function. print is sometimes mistaken as a function by many programmers since it sets a return value, but it is also a language construct like echo. It simply outputs a string of data. And you are not required to use parentheses with it.

Example code













Output will be the same.

how to use Code Comments PHP Scripts


Commented lines do not get processed by the browser or PHP. They get skipped over like they do not exist. They are made only for human reading.

Why programmer use code comment ?

1. Remind us what our code sections are doing long after we have created them.
2. In good HTML editors it makes a nice colored divider between code sections.
3. Place author name and script creation date information.
4. Make it easier for other developers and programmers to adapt and work with your code.

 In below example there are different types of comment code .

27 Feb 2013

SYNTAX -- php tags

Where to place PHP code ?
First open notepad and Copy below images code in notepad or whatever your PHP-editor and save as abc.php (You can change file name but not extension) in your newproject folder (You can change the path but it should be in htdocs folder).
eg. c:\xampp\htdocs\newproject\abc.php

When PHP parses a file, it looks for opening and closing tags, which tell PHP to start and stop interpreting the code between them.

1.1st type is like this in below image.


2.Alternately you can choose to have many PHP blocks exactly located in the HTML Head or Body section of the document where that certain data would display. which is wrote in below image.


3. You can also write like below code.

26 Feb 2013

How to setup environment for PHP ?
AND
How to run PHP file ?

1. Download XAMPP from HERE .

2. Install it in your system. for more info. how to install Click Here

3. After installation reboot your system.

4. Open XAMPP control panel and start TOMCAT , APACHE , MYSQL.


5. To check that XAMPP is working or not Open your web browser and type localhost in address bar and enter.

if your page is not look like upper image that means there is some problem with your XAMPP.

6. C:\xampp\htdocs\ is the root of your web server. This is the place of our webpages.

7. Then for starting new project Go to the C:\xampp\htdocs\newproject or whatever your folder name you want.


8. For opening your project open the web browser and type localhost/newprject/index.php in address bar.

NOTE:here i already created a php page in C:\xampp\htdocs\newproject\ with name of index.php

9. We will see the PHP code in next post.

25 Feb 2013

Introduction


What is PHP?
PHP is an acronym for Hypertext Preprocessor. It is a dynamic server side scripting language that allows an application developer to create very simple to very complex mechanisms for the web.


Why Learn PHP?
1. Relatively easy to learn and understand.
2. Processes data fast and dynamically.
3. Most dynamic web applications being made today have a PHP core (brain).
4. Free Open Source Technology.
5. Processes online forms and sends emails.
6. Create files and directory folders out of thin air.
7. PHP can run on Linux as well as Windows server.
8. Its Object Oriented Language.
9. Huge Free online resource databases for classes and functions.
10. More than 700 Built-In functions.