Sabtu, 05 Mei 2012

php Strings

String is the collection of characters which is stored in a single variable. PHP provides many in-built functions to use strings.
We need to enclose the string within double quote or single quote. We can store any string value into a variable or we can print the value directly instead, depends upon the need.
We can use both single and double quote for string creation. Now php introduces more robust technique called heredoc method to create string of multiple line.

echo 'This is the first string within single quote<br/>';
echo "This is the second string within double quote<br/>";
$string="Value from string variable";
echo $string;
This is a multiple line string
using heredoc method.
echo "<br/>";
echo $string;
This is the first string within single quote
This is the second string within double quote
Put some value to string variable
This is a multiple line string using heredoc method.

php Operators:

Operators are one of the important feature of every language. In php operators are classified in following categories:

Arithmetic Operators
Name Symbol Example Output
Addition + 2+2 4
Subtraction - 2-2 0
Division / 2/2 1
Multiplication * 2*2 4
Modulus % 2%2 0
Increment ++ let $x=2
Decrement -- let $y=5
Negation - let $a=2

Comparison Operator
Name Symbol Example Output
is equal = = 2= =2 True
is not equal != 2!=1 True
is not equal <> 2!=2 False
is greater than > 2>1 True
is less than < 3<4 True
is less than equal <= 2<=4 True
is greater than equal >= 2>=4 False

php basic syntax

In the given tutorial we will study how to write the basic syntax of php:
The above mentioned tag will be included in each php file and each php coding has to be written within this tag.
echo "Hello World";
The above coding will print Hello World in the output screen or web page.

We can combine both php and html file in a single file, following example illustrates that:
<body>This is html portion<br/></body>
echo"This is in php portion";
This is html portion
This is in php portion

php syntax is more or less similar to any other popular language like: C, ASP, Java etc. In this language semicolon is as important as other language. There are many more similarities are also present like in php white spaces don't make any special difference.
portion"; Thisis in php

This is in php portion