<? PHP
/**
* @ Author ADIM
* @ Copyright 2009
* @ Version
* @ Data_seek (Thursday, April 20
*/
Echo "Hello World ~~~ This is my first PHP project. Haha ~~ <Br> "; // line feed in PHP
Print "Yes? Congratulations, good <br> ";
/**
* Custom Variables
*/
$ STR = "this is a string variable"; // note that the $ symbol is good and the variable name is tight.
$ Botrue = true; $ bofalse = false; // when declaring a custom variable, it can only be an underline. A-Z, A-z
$ Math = 15;
$ Mathlong = 2.0144;
$ Arr = array (1, 2, "Hell world", 2, 3, 4 );
$ Arr2 = array ("ID" => 100, "tile" => 200); // the key value must be written as =>, but cannot be written as> =
Echo $ STR;
Print ("<br> ");
Print ($ bofalse );
Print ("<br> ");
Echo $ botrue;
Print ("<br> ");
Echo $ math;
Print ("<br> ");
Echo $ mathlong;
Print ("<br> ");
/**
* Comparison Operators
*/
Echo 1 = 4; // when the comparison operator is true, output 1 is displayed. When the comparison operator is false, nothing is output.
Echo 1 = '1 ';
Echo 9> 1;
Print ("<br> ");
$ A = 8;
Echo $ A ++;
Echo "<br> ";
Echo ++ $;
Echo "<br> ";
/**
* Judgment statement
*/
If ($ A = 8)
{
Echo "equal to 8 ";
}
Elseif ($ A = 10 ){
Echo "equal to 10 ";
Echo "<br> ";
}
Else
{
Echo "error ";
}
Switch ($)
{
Case 0: ECHO ("your output time is zero ");
Break;
Case 1: ECHO ("You output 10 ");
Break;
Default: Echo "no matching ";
}
/**
* Do While () and while (), for ($ I; $ I <10; $ I ++) Loops
*/
Do {
Echo "do while execution result $ ";
} While ($ A> 10 );
While ($ A> 10)
{
Echo "execution result $ ";
};
Echo "<br> ";
For ($ I = 1; $ I <= 9; $ I ++)
{
For ($ k = 1; $ k <= 9; $ K ++)
{$ C = $ I * $ K;
Echo "$ I * $ k = $ C"; // variables can be directly referenced in double quotes in PHP, but the output in Java, JS, C, C # is a constant.
}
Echo "<p> ";
};
Echo "<p> ";
Echo "the first value of the referenced array is $ arr [0]";
Echo "the key value corresponds to $ arr2 [tile]";
Echo "<p> ";
Print_r ($ ARR );
Echo ("<br> ");
Print ("The following is a two-dimensional array test <br> ");
$ Arr3 = array (Array (3, 8), array (9, 10 ));
Print_r ($ arr3 );
Echo $ arr3 [0] [1];
Echo "<br>"; // <! -- Phpdesigner: Timestamp [22:21:53] -->
Foreach ($ arr3 as $ key1 => $ value1)
{
Foreach ($ value1 as $ key2 => $ value2)
{
Echo ("The key is $ key2 and the value is $ value2 ");
Echo "<br> ";
}
}
$ Arr4 = array (1, 3, 5, 7, 9 );
Foreach ($ arr4 as $ key => $ value)
{
Echo "<br> ";
Echo ("The key is $ key and the value is $ value ");
}
Print ("<br> ");
Echo "The following are user-defined functions <br> ";
/**
* _ Zidingyi ()
*
* @ Return
*/
Function _ zidingyi ()
{
Return "this is ower's function (this is a custom function with no parameters returned )";
};
$ Zi = _ zidingyi ();
Echo ($ Zi. "<br> point numbers can be used for connection in PHP, which is different from the plus signs used in Java <br> ");
If (function_exists ("_ zidingyi "))
{
Echo ("This function already exists <br> ");
} Else {
Echo "This function does not exist yet <br> ";
}
/**
* _ Ziexitsparameter ()
*
* @ Param mixed $ Val
* @ Param integer $ val2
* @ Return
*/
Function _ ziexitsparameter ($ Val, $ val2 = 2)
{
$ A = $ Val * $ val2;
Return $;
}
$ Func = _ ziexitsparameter (2,-5.5 );
Echo ($ func. "This is the value returned by the function with a selection <br> ");
Echo "The following are system functions <br> ";
$ Sysmd5 = MD5 ("Yang fuchao ");
Echo ("My name (Yang fuchao) is encrypted with $ sysmd5 <br> ");
$ Sys = date ("Y-m-d ");
Echo ($ sys );
$ Sucess = @ mysql_connect ("localhost", "root", "admin") or die ("connection error"); // @ symbol hiding error, or die () indicates selecting
$ SQL = "select * from test ";
Mysql_select_db ("PhP100", $ sucess );
If ($ sucess)
{
Echo ($ sucess. "MySQL database connection successful <br> ");
}
Else
{
Echo ($ sucess. "MySQL database connection failed <br> ");
}
// Phpinfo ();
?>
<Font color = 'red' size = '8'> mix HTML and PHP. The following is Php. </font>
<?
Phpinfo ();
?>