The code is as follows:
Download nearby: Http://files.cnblogs.com/great/MyPHPTest.rar
hello.php
<title>My first PHP program</title>
Error occurred:[$error _level] $error _message
"Echo" is about to stop the execution ... ";d ie ();} Set_error_handler ("Customerror", e_user_warning); */*? E_user_error-Fatal user generated run-time error. The error cannot be recovered. The script execution was interrupted. E_user_warning-A non-fatal user-generated run-time warning. Script execution is not interrupted. E_user_notice-Default. User-generated Run-time notifications. The script found a possible error, or it might occur when the script is running normally. */$testNum =0;if ($testNum >1) {trigger_error ("parameter must be less than 1. ");} echo "
"; function Checknum ($num) {if ($num > 1) {throw new Exception (" value must be less than 1 ");} return true;} Try{checknum (0); echo "You passed the number parameter correctly!" ";} catch (Exception $e) {echo "Call Checknum () method, exception is caught, exception information:". $e->getmessage ();} Class Mycustomexception extends Exception{public function errormessage () {$ERRORMSG = ""Error line number:". $this->getline (). ", in. $this->getfile ()." :". $this->getmessage ()." ""; return $ERRORMSG;}} echo "
function Checkprice ($tempPrice) {if ($tempPrice >) {throw new Mycustomexception ("Price cannot be greater than 100");} return true;} Try{checkprice, echo "Your incoming price parameter is correct!" ";} catch (Mycustomexception $e) {echo "Call Checkprice () method, exception is caught, exception information:". $e->errormessage ();} echo "
"Function Currentpageexception ($EX) {echo"An error has occurred on the current page! Info: ". $ex->getmessage ()."";} Set_exception_handler ("Currentpageexception");//throw new Exception ("Throws Exception exception! "); echo "
";//throw new Mycustomexception (" throws the Mycustomexception exception!) //this is a comment/* to let PHP display error, modify the configuration file php.ini, change display_errors = off to On*/echo "Hello world, I Am Jay Chou";? >
"; Print "Length:". strlen ($myWord). " (Hint: Because this file encoding method is UTF8, in PHP, a Chinese length of 3, the length of the English is 1, if the encoding of this file is GB2312, then the length of a Chinese character is 2 bytes)
"Echo $myWord." Long live China ". $myWord;//echo ($myWord);//print ($myWord); echo" string \ "Bruce Bruce Liu, the best" in Liu's position: ". Strpos (" Bruce Bruce Liu is the best ", "Liu"). "
"If (4>5) {echo" If execution
";} ElseIf (4==5) {echo] ElseIf execution
";} Else{echo "Else execution
";} $x = "Hello"; switch ($x) {case "Bruce": Echo "Number 1"; Break;case "Hello": echo "Number 2"; Break;case "Hello": echo "Number 3"; Break;default:echo "No number between 1 and 3";} echo "
"; $names = Array (" AAA "," BBB "," CCC "); Echo $names [1];echo]
"; $ages = Array (" AAA "=>18," BBB "=>19," CCC "=>28); Echo $ages [" CCC "];echo"
"; $families = Array (" MMM "=>array (" name "=" Bruce "," Age "=>18," Sex "=>true)," nnn "=>array (" name "=" Kim "," Age "=>19," Sex "=>false)," KKK "=>array (" name "=" Yage "," Age "=>20," Sex "=>true); echo" Name: ". $ families["KKK" ["Name"]. ", Gender:". $families ["KKK"] ["Sex"];echo "
"If ($families [" nnn "] [" sex "]) {echo $families [" nnn "] [" name "]." of Sex for men! ";} Else{echo $families ["nnn"] ["name"]. " of sex for women! ";} echo "
The while loop, do-while loop, and for loop in PHP are similar to other languages! The following focuses on the Foreach loop:
"; foreach ($names as $nameItem) {echo" name: ". $nameItem."
";} echo "
"Function Add ($num 1, $num 2) {return $num 1 + $num 2;} echo "3.5+5=". ADD (3.5,5/* If the second argument is true, the result is 4, because true has an integer value of 1 */); echo "
echo Date ("y/m/d"); echo "
";/* Syntax Mktime (HOUR,MINUTE,SECOND,MONTH,DAY,YEAR,IS_DST) */$tomorrow = Mktime (0,0,0,date (" M "), Date (" D ") +1,date (" Y ") ); echo "Tomorrow is". Date ("y/m/d", $tomorrow);? >
Read file
"; }fclose ($file);}? >
";} Session_Start ();/*session saved cookie name: phpsessid*/if (!isset ($_session["CurrentUserName"]) {$_session[" CurrentUserName "] =" Zhang San ";} Else{echo $_session["CurrentUserName"];//unset ($_session[' currentusername ']);/* the unset () function is used to release the specified SESSION variable */// Session_destroy (); /* Session_destroy () function completely terminate session */}/* Send Message syntax: Mail (to,subject,message,headers,parameters) $to = " Testzhangsan@163.com "; $subject =" Test mail "; $message =" hello! A simple email message. "; $from = "testzhangsan@gmail.com"; $headers = "From: $from"; Mail ($to, $subject, $message, $headers); echo "Mail Sent."; */?>function filtering
"; echo" integer range Validation: "; $numRange = Array (" Options "=>array (" Min_range "=>0," Max_range "=>30));//Note: The options above, min _range, Max_range cannot write wrong if (!filter_var ($num 1,filter_validate_int, $numRange)) {echo ' integer must be between 0 and 30! ";} Else{echo "The range of integers you entered is legal! ";} echo "
"; function Convertspace ($words) {return Str_replace (" _ "," ", $words);} $string = "Pi _ _ _ _ _ _ _ _ _ _ _ People!"; Echo Filter_var ($string, Filter_callback, Array ("Options" = "convertspace"));? >
dosubmit.php
Post Submission
The information you submitted is as follows.
Name:
Age:
Get Commit
The information you submitted is as follows.
Name:
Age:
doupload.php
File Upload
The information you submitted is as follows.
0) {echo ' Upload error! Information: ". $_files[" Yourphotos "[Error"]. "
";} else{/* file name: EditPlus V3.20.400 Chinese green Edition. RAR type: Application/octet-stream size: 1093.7607421875KB storage path: c:\windows\temp\php2b.tmp*/$currentFileName = $_files[" Yourphotos "[" name "]; $currentFileType = $_files[" Yourphotos "[" type "]; $currentFileSize = $_files[" Yourphotos "[" Size "]; $currentFileTmp _name = $_files[" Yourphotos "[" Tmp_name "];echo" file name: ". $currentFileName."
"; echo" type: ". $currentFileType."
"; echo" Size: ". ($currentFileSize/1024). " Kb
"; echo" Temporary storage Path: ". $currentFileTmp _name."
"If (file_exists (" uploadedfiles/"). $currentFileName) {echo $currentFileName. "Already exists! ";} Else{move_uploaded_file ($currentFileTmp _name, "uploadedfiles/". $currentFileName); echo "Persistent storage path:". "Uploadedfiles/". $currentFileName;}}? >
Thanks for browsing!