|What is PHP|
|What is echo|
|What is print|
|Increment Decrement Operator|
|If ElseIf Else|
|Do While loop|
|Require vs Include|
If you’re reading this book, you probably already know what PHP is—one of the world’s most popular programming languages for Web application development. Widely available and backed by the support of a vociferous and enthusiastic user community, the language was in use on more than 20 million Web sites at the end of 2006…and that number is only expected to grow..!
Personally, I’ve always believed the reason for PHP’s popularity to be fairly simple. It has the unique distinction of being the only open-source server-side scripting language that’s both easy to learn and extremely powerful to use. Unlike most modern server-side languages, PHP uses clear, simple syntax and delights in non-obfuscated code; this makes it easy to read and understand, and encourages rapid application development. And then of course, there’s cost and availability.
PHP is available free of charge on the Internet, for a variety of platforms and architectures, including UNIX, Microsoft Windows, and Mac OS, as well as for most Web servers.
PHP (Hyper text Pre Processor) is a scripting language commonly used for web applications. PHP can be easily embedded in HTML. PHP generally runs on a web server. It is available for free and can be used across a variety of servers, operating systems and platforms.
The echo statement can output one or more string. The echo statement can display anything that can be display to the browser, such as string, variable value, number, the result of expression etc.
Echo is a language construct not actually a function. You can used it without parentheses e.g echo or echo(). If you want to pass more than one parameter to echo, the parameter must not be enclosed within parentheses.
The print statement can also use for displaying the output to the browser. The print is also a language construct not a real function. So can also use it without parentheses like: print or print().
The echo and print both statement are work exactly the same way except that the print statement can only output one string, and always return 1. That’s way the echo statement considered marginally faster than the print statement since is doesn’t return any value.
Variable is name given to the storage area and its value change during programming execution is known as variable. The variable are use to store data. like number of arrays.
PHP variables begin with a dollar sign ($) as shown below.Syntax
$var_name = "Value";
|boolean||True or false|
|array||TList of items|
|object||Install of a class|
<?php $Greeting = 'Hello World!'; ?> <html> <head> <title><?php echo $Greeting; ?></title> </head> <body> <?php echo $Greeting; ?> </body> </html>O/P
A variable's scope determines the locations from which the variable can be accessed.PHP variables are either super global, global, or local.
Superglobal variables are predefined arrays, including $_POST and $_GET. They are accessible from anywhere on the page.The complete list of super global is shown below.
Global variables are visible throughout the script in which they are declared. However, they are not visible within functions in the script unless they are re-declared within the function as global variables
Variables in the function scope are called local variables. Local variables are local to the function in which they are declared.
Constants are like variables except that, once assigned a value, they cannot be changed. Constants are created using the define() function and by convention (but not by rule) are in all uppercase letters. Constants can be accessed from anywhere on the page.
A constant Is a identifier for a simple value. As the name suggest, that value cannot change during execution of the script.Syntax
When comparing or processing variables and other values you use operators. Without them, PHP would be more of a word jumble instead of a language. In some unique cases, operators slightly alter the relationship between two variables or their function within PHP. Without further adieu, here they are.
|Add ( + )||$a = 1; $a = $a + 5; // $a is equal to 6|
|Subtract ( - )||$s = 10; $s = $s - 5; // $s is equal to 5|
|Multiply ( * )||$m = 2; $m = $m * 10; // $m is equal to 20|
|Divide ( / )||$d = 20; $d = $d / 5; // $d is equal to 4|
|Modulus ( % )||Provides the remainder after division: $u = 5; $u = $u % 2; // $u is equal to 1|
|Add ( += )||$a = 1; $a += 5; // $a is equal to 6|
|Subtract ( -= )||$a = 1; $a += 5; // $a is equal to 6|
|Multiply ( *= )||$m = 2; $m *= 10; // $m is equal to 20|
|Divide ( /= )||$d = 20; $d /= 5; // $d is equal to 4|
|Modulus ( %= )||Provides the remainder after division: $u = 5; $u %= 2; // $u is equal to 1|
|Concatenate ( .= )||Join onto the end of a string: $c = 5; $c .= 2; // $c is now a string, '52'|
|Greater Than ( > )||2 > 1|
|Less Than ( < )||1 < 2|
|Greater Than or Equal To ( >= )||2 >= 2 3 >= 2|
|Less Than or Equal To ( <= )||2 <= 2 2 <= 3|
Increment ( $integer++; )
Decrement ( $integer--; )Example:
$a = 1; $a = $a + 1; // $a is now equal to 2 $a++; // $a is now equal to 3 $a--; // $a is now equal to 2 again, same as $a = $a – 1;
The Ternary Operator is a short-hand form for evaluating what to do when an expression is evaluated as either TRUE or FALSE. The conditional returns either the TRUE or FALSE output. Basic format is as follows:
(expr) ?ValueIfTrue :ValueIfFalse ;Examples:
$boolean = TRUE; $result = ($boolean) ? 'Is True' : 'Is False'; echo $result; Is True // $result is not yet set $result = (isset($result)) ? $result+1 : 10; echo " \$result = $result."; $result = (isset($result)) ? $result+1 : 10; echo " \$result = $result."; $result = 10. $result = 11.
When it comes to altering the case of a string, PHP makes it easy with four built-in functions. Two of them are illustrated previously: the strtoupper() function uppercases all the characters in a string, while the strtolower() function lowercases all the characters in a string.
For more precise control, consider the ucfirst() function, which capitalizes the first character of a string (good for sentences), and the ucwords() function, which capitalizes the first character of every word in the string (good for titles).Here’s an example:
<?php // define string $rhyme = "and all the king's men couldn't put him together again"; // uppercase first character of string // result: "And all the king's men couldn't put him together again" $ucfstr = ucfirst($rhyme); echo $ucfstr; // uppercase first character of every word of string // result: "And All The King's Men Couldn't Put Him Together Again" $ucwstr = ucwords($rhyme); echo $ucwstr; ?>