Skip to main content

PHP (PHP: Hypertext Preprocessor)

PHP (PHP: Hypertext Preprocessor)
What is PHP?
PHP stands for PHP: Hypertext Preprocessor. It is a web development language written by and for web developers. The product was originally named Personal Home Page Tools. PHP is an open source, server side, HTML-embedded web scripting language usually used to create web applications in combinations with a web server, such as Apache. It enables the user to embed code fragments in normal HTML-page. It also makes the connection of a web page to server-side databases. It can also be used to create command-line scripts akin to Perl or shell scripts.  
HTML-embeddedness
PHP can be easily embedded within HTML-page. In other words, PHP pages are ordinary HTML pages that escape into PHP mode only when necessary. PHP codes are embedded with the help of canonical php tags.
 <? php 
 ?>
 Following is an example-
<html>
<head>
<title> Greeting </title>
</head>
<body>
<p> hello,
<? php
//php mode
$firstname=”Raj”;
$secondname=”Kumar”;
echo “$firstname”. ”$secondname”;
?>
This is my first PHP program.
</p>
</body>
</html>
OUTPUT
Hello, Raj Kumar This is my first PHP page.

INCLUDING FILES
A PHP file can be embedded in an HTML page by putting it in a separate file and calling it by using PHP’s include functions:
·         include (‘/filepath/filename’)
·         require (‘/filepath/filename’)
·         include_once (‘/filepath/filename’)
·         require_once(‘/filepath/filename’)

VARIABLES

To store information in a php program is by using a variable- a way to name and hang on to any value that a user wants to use later.
Important points to know about variables in PHP are-
·        All variables are denoted with a leading dollar sign.
·        The value of a variable is the value of its most recent assignment.
·        These are assigned with the = operator, with expressions on right hand side and variables on left.
·        They can, but do not need to be declared before assignment.
·         Variables which are used before they are assigned have default values.
·        They do not have intrinsic type other than the type of their current value.

Syntax for assigning a variable is as follow:
·        $my_var = 5;  //integer type
·        $my_var = “Hello world”;  //string type
·        $var = 3.56; //float value


CONSTANTS
PHP offers constants which have a single value throughout their lifetime. They do not have a $ before their names, and by conventions the names of constants usually are in uppercase letters. They can contain only scalar values, with global scope.
It is possible to create constants using the define() function.
define (my_var, 45);

TYPE SUMMARY
PHP has a total eight types: integer, double, Boolean, strings, arrays, objects, NULL, and resources.
·        Integers are whole numbers, without a decimal point, like 579.
·        Doubles are floating-point numbers, like 3.1567 or 5.00.
·        Booleans have only two possible values: TRUE and FALSE.
·        NULL is a special type that has only one value: NULL.
·        Strings are sequences of characters, like “hello world”, ‘my name is xyz’.
·        Arrays are named and indexed collections of other values.
·        Objects are instances of programmer-defined classes.
·        Resources are special variables that hold references external to PHP (such as database connection).

OUTPUT
The two most basic constructs for printing to output are echo and print. Their language status is somewhat confusing because of their basic constructs of the PHP language rather than being functions. They can be used either with parentheses or without them.
ECHO
The simplest use of echo is to print a string as argument. For e.g.
echo “this is my php page”;
Or
echo (“this is my php page”); 
We can also give multiple arguments to the Unparenthesized version of echo but not in Parenthesized version of echo.
Echo “this is my php page”. “Hello world”;
PRINT 
The print command is very much similar to echo, with mainly two important differences-
·        Unlike echo, print can accept only one argument.
·        Print returns a value, which represents whether or not the print statement succeeded.
·        The value returned by print is always 1.

print (“3.1567”);   //print a string
print (3.1577);    // print a number

USING FUNCTIONS
A function is a way of wrapping up a chunk of code and giving that chunk a name, so that the programmer can use that chunk later in just one line of code.
The most basic syntax of calling (or using) a function is-
function_name (expression 1, expression 2, …, expression n);
The function name is followed by a parenthesized and a comma-separated list of input expressions, they are called arguments to a function. Functions can be called with zero or more arguments depending on their definition.
Built-in Functions-
The following are valid calls to built-in PHP functions-
·        sqrt (9); //square root function, returns 3
·        rand (10, 10+10); //random number between 10 and 20
·        strlen (“hello world”); //returns the length of the string, 10
·        pi (); //returns the approximate value of pi
User-defined Functions-
function function_name ($argument 1, $argument 2, …)
{
Statement 1;
Statement 2;
}
Function definition has four parts-
·        The special word function
·        Name of the function
·        Parameter list- dollar sign separated by commas
·        The function body





Comments

Popular posts from this blog

Advantages and Disadvantages of EIS Advantages of EIS Easy for upper-level executives to use, extensive computer experience is not required in operations Provides timely delivery of company summary information Information that is provided is better understood Filters data for management Improves to tracking information Offers efficiency to decision makers Disadvantages of EIS System dependent Limited functionality, by design Information overload for some managers Benefits hard to quantify High implementation costs System may become slow, large, and hard to manage Need good internal processes for data management May lead to less reliable and less secure data

Inter-Organizational Value Chain

The value chain of   a company is part of over all value chain. The over all competitive advantage of an organization is not just dependent on the quality and efficiency of the company and quality of products but also upon the that of its suppliers and wholesalers and retailers it may use. The analysis of overall supply chain is called the value system. Different parts of the value chain 1.  Supplier     2.  Firm       3.   Channel 4 .   Buyer

Big-M Method and Two-Phase Method

Big-M Method The Big-M method of handling instances with artificial  variables is the “commonsense approach”. Essentially, the notion is to make the artificial variables, through their coefficients in the objective function, so costly or unprofitable that any feasible solution to the real problem would be preferred, unless the original instance possessed no feasible solutions at all. But this means that we need to assign, in the objective function, coefficients to the artificial variables that are either very small (maximization problem) or very large (minimization problem); whatever this value,let us call it Big M . In fact, this notion is an old trick in optimization in general; we  simply associate a penalty value with variables that we do not want to be part of an ultimate solution(unless such an outcome is unavoidable). Indeed, the penalty is so costly that unless any of the  respective variables' inclusion is warranted algorithmically, such variables will never be p