Tuesday 15 February 2011

PHP

<html>
<body>

<?php
echo "Hi there!";
$txt="Hi there!"; //a variable containing a string
echo $txt

$txt1="Hi!";
$txt2="What a nice day!";
echo $txt1 . " " . $txt2; //the concatenation operator

$var_name = value;
$d=date("D");
if ($d=="Fri") echo "Have a nice weekend!"; //if statement

$d=date("D");
if ($d=="Fri")
  echo "Have a nice weekend!";
else
  echo "Have a nice day!"; // if..else statement

$d=date("D");
if ($d=="Fri")
  echo "Have a nice weekend!";
elseif ($d=="Sun")
  echo "Have a nice lazy Sunday!";
else
  echo "Have a good day!"; // if...elseif....else Statement

$cars[0]="Mini Cooper";
$cars[1]="Rover";
$cars[2]="BMW";
$cars[3]="Toyota";
echo $cars[0] . " and " . $cars[1] . " are BRITISH cars."; // Numeric array: Mini Cooper and Rover are BRITISH cars.

$ages['James'] = "37";
$ages['John'] = "44";
$ages['Anthony'] = "43";

echo "James is " . $ages['JAMES'] . " years old."; // JAMES is 37 years old.
$x=array("ding","dang","dong");
foreach ($x as $value)
  {
  echo $value . "<br />";
  } // ding
       dang
       dong

function writeName()
{
echo "Michael James Snyder";
}

echo "My name is ";
writeName();
?> // PHP Function: My name is Michael James Snyder

function writeName($fname)
{
echo $fname . " Snyder.<br />";
}

echo "My name is ";
writeName("Michael James");
echo "My sister's name is ";
writeName("Wendy");
echo "My brother's name is ";
writeName("John");
?> // My name is Michael James Snyder.
      My sister's name is Wendy.
      My brother's name is John Snyder.

Welcome <?php echo $_POST["fname"]; ?>!<br />
You are <?php echo $_POST["age"]; ?> years old. // Form:
// Welcome John!
// You are 44 years old.

$tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
echo "Tomorrow is ".date("Y/m/d", $tomorrow); // Tomorrow is 2011/02/16

?>



<html>

/* HTML creates user interfaces, but to create dynamic websites, or to transfer data from a Web page to another database program, use PHP Hypertext Processor (www.php.net). Dynamic web pages need to respond to the user, and need to retrieve information off a Web page and store it in a database, such as when you type your credit card number to buy something off a Web site. PHP is a popular programming language for running programs on Web servers (those computers responsible for displaying and retrieving information from Web pages, such as shopping data. PHP programs can run only on Web pages under many different operating systems. PHP mimics the syntax from C and Perl. */
<body>
/* If a comment extends over multiple lines,
It’s easier to use these types of comment
symbols instead. */
<?php // single line comment: The <?php and ?> tags define the beginning and ending of a PHP program.
echo “<h1>Greetings from PHP.</h1>”;
</body>
?>
# This is the end of the PHP program
</html>
// PHP program scripts are stored in a file that ends with the .php file extension.

$VariableName = value; // Declare any type of data; a variable holds a string or a number
VariableName
$MyAge // variable 1 is case sensitive
$myage // variable 2 is case sensitive

$myage = 38; //$myage variable is initially set to 38
$yourage = $myage; // the $myage variable also contains the value of 38
$myage = 103; // this line now stores the value 103 into the

$myage = 38;
$yourage = &$myage;
//Reference a variable with the ampersand symbol (&)
// allow a variable to contain identical data without specifically assigning those values.
// The $yourage variable references the $myage variable
// whatever value the $myage variable contains from now on will automatically get stored in the $yourage variable.
$myage = 103; //the $myage variable now contains the value of 103, so the $yourage variable contains 103 too.

if (condition) {
Command;
}

if (condition) {
Command;
}
else {
Command;
}


if (condition1) {
Command;
}
elseif (condition2) {
Command;
}
elseif (condition3) {
Command;
}


switch (expression) {
// use regular expressions that are built-into PHP to implement a finite automaton search algorithm
case value1:
Command;
break;
case value2:
Command;
break; // include the break command to tell the computer when to exit out of the SWITCH statement.
default:
Command;
}

if (expression == value1) {
// use regular expressions that are built-into PHP to implement a finite automaton search algorithm
Command;
}
elseif (expression == value2) {
Command;
}
else {
Command;
}
switch (expression) {
// use regular expressions that are built-into PHP to implement a finite automaton search algorithm
case value1: // check if a variable matches multiple values
case value2: // stack multiple case statements
Command;
break;
case value3:
case value4;
Command;
break;
default:
Command;
}
if (expression == value1) || (expression == value2) {
Command;
}
else if (expression == value3) || (expression == value4) {
Command;
}
else {
Command;
}

for (startvalue; endvalue; increment) { // a loop that repeats for a fixed number of times
Command; // loop until a certain Boolean condition becomes True
}

for ($i = 1; $i <= 4; $i++) { // The FOR loop runs four times, set the Start value to 1 and the End value to 4
Command;
}
while (condition) { // I don’t know how many times I need to repeat commands here
Command; // If the condition is True, the loop runs at least once. If this condition is False, the loop doesn’t run.
}

function functionname (Parameter list)
// this is a subprogram that solves a specific task
// The Parameter list defines any data that the function needs to work.
// If the function doesn’t need to accept any values, the parameter list can be empty.
{
Commands;
return $value; // Defines a value to return.
}

function myfunction () // This function doesn’t return a value or accept any parameters

{
Command;
}
$arrayname[index] = data;
/*Arrays can hold any type of data and grow as large as I need them without having to define a size ahead of time.
To create an array, I define an array name, the data I want to store, and the index number where I want to store that item in the array*/

$myarray[0] = “Hello”; // I want to store the string “Hiya”
$myarray[1] = 3.57; // I want to store the number 3.57 in the first and second elements of an array

$arrayname[“key”] = data; // I create associative arrays to  identify data by a unique string key not an index number

$myarray[“pi”] = 3.14; // I assign the number 3.14 to the “pi” key

$variable = $arrayname[“key”]; I use the key value to retrieve data from an associative array

$myarray[“pi”] = 3.14;
// I want to retrieve data stored under the key “pi
// This first line stores the value 3.14 into the array and assigns it to the key “pi”.
$number2use = $myarray[“pi”];
// This second line pulls out the data, associated with the key “pi”
// This stores that data into the $number2use variable.
// “array_pop” is a built-in array functions for manipulating arrays
// “array_pop” removes the last element from an array
// “array_push” adds an element to the end of an array
// “sort” sorts arrays in ascending order

class classname {  // define a class
public $propertyname; // specify the property to create an object
public function methodname() { // specify the methods to create an object
commands;
}
}

$objectname = new classname; // I use this Syntax to create an object

$objectname->propertyname = value;
// I specify the object name and the property you want to use to assign a value to an object’s property
// the dollar symbol is not used when assigning a value to an object’s property
// ($) isn’t used to designate the property name.

$objectname->methodname();
// specify the object name followed by the method name to tell an object to run a method

class classname1 {
public $propertyname;
public function methodname() {
commands;
}
}
class classname2 extends classname1 {
// use the extends keyword followed by the class name you want to inherit from to inherit from a class
// an object can inherit from one class
// This is “single inheritance” in Object Oriented Programming
public $propertyname;
public function methodname() {
commands;
}
}

include_once "a.php"; // this will include a.php
/*include is a directive or statement that causes another PHP file to be included and evaluated*/

3 comments:

Anonymous said...

PHP is good with CUrl for opening persintant connections to servers for communication.

Anonymous said...

good well established OSS

Anonymous said...

Eclipse includes tools made to give developers the freedom of choice in a multi-language, multi-platform, multi-vendor environment. Eclipse provides a plug-in based framework that makes it easier to create, integrate, and utilize software tools, saving time and money. By collaborating and exploiting core integration technology, tool producers can leverage platform reuse and concentrate on core competencies to create new development technology. The Eclipse Platform is written in the Java language and comes with extensive plug-in construction toolkits and examples.