Php learning 00

Source: Internet
Author: User
Tags echo name
: This article mainly introduces php learning 00. if you are interested in the PHP Tutorial, you can refer to it.

  Global variables, Subscript isGlobal variablesName, which can also be used inside the function. you can use this array to directly updateGlobal variables* Static keyword * is used to declare a local variable inside the function. this variable will not be destroyed after the function is called, that is, it is stored in the heap instead of in the stack */$ x = 5; $ y = 10; functionmyTest () {$ y = 10; echo "variable x is :". $ x; echo"
"; Echo" variable y: $ y ";}// myTest (); // echo" variable x: ". $ x; // echo"
"; // Echo" variable y: $ y "; // print_r ($ GLOBALS); functionmyTest1 () {global $ x, $ y; echo" x variable is: $ x "; echo"
"; Echo" variable: $ y "; echo"
"; $ Y = $ x + $ y; echo" x + y: $ x + $ y ";}// myTest1 (); // echo"
"; // Echo" y = $ y "; functionmyTest2 () {static $ x = 0; echo $ x ."
"; $ X ++;} // myTest2 (); // myTest2 (); // myTest2 (); // myTest2 (); /** echo and print * echo can output at least one character string * print can only output one character string, and 1 * echo is returned as a statement without (), plus () * echo is slightly faster than print, because no return value * print is also the statement does not have (). You can also add () *** // echo "ddddd "; // echo 'I', "am", 'xue '; // print"
"; // Print" I ";/** php Data type * 1. string 'AAA', "aaa" * 2. an integer in the format of * decimal * hexadecimal 0x starting with * octal 0*3. floating point type, including small trees, or indexes * 10.45, 2.4e5, 2.3e-3 * // $ x = 123; // var_dump ($ x ); // $ y = 0x456; // var_dump ($ y); // $ z = 015; // var_dump ($ z); // $ a = 0.3; // var_dump ($ a); // $ B = 0.3e2; // var_dump ($ B);/** array: ** // ** NULL indicates that the variable value is NULL ** // * string function * 1. strlen () returns the length of the string * 2. strpos () searches for substrings or substrings * returns the first position of the searched character or string in the original string (starts with 0) * if not found, FALSE * // $ str = "123"; // $ len = strlen ($ str); // echo $ len; // $ str1 = "woshixue "; // var_dump (strpos ($ str1, "ee");/** constant: * constants are similar to Variables. once defined, the definition cannot be undone or changed, after being defined as a global scope * the constant * define ('name', 'value' cannot be modified in the script. optional (the default value is false ,)) * // define ("NAME", "xuexinghai", false); // echo name ;/**Loop: * For, foreach, while, do... while * // $ arr = array ("apple", "orange", "banana"); // foreach ($ arr as $ v) // echo $ v."
";/** Array * 1. array declaration * directly declare * join * 2 count to get the number of array elements * // directly declare // $ arr = array (); // $ arr [0] = 3; // $ arr [1] = "xue"; // var_dump ($ arr ); /// join definition // $ arr1 = array ("name" => "xue", age => 25); // var_dump ($ arr1 ); /// define a two-dimensional array // $ arr2 = array (// 0 => $ arr, // 1 => $ arr1 //); // var_dump ($ arr2); // $ arr3 [] = $ arr1; // $ arr3 ['XXX'] = $ arr2; // $ arr3 [7] = 33; // var_dump ($ arr3); // $ arr4 = array (); // var_dump ($ arr4 ); //// echo "the elements of arr4 are:", count ($ arr4); // array sorting // 1. sort, sort the array in ascending order // *** SuperGlobal variables, You can use * $ GLOBALS to save allGlobal variables* $ _ SERVER saves the header, path, and the script location * $ _ REQUEST the user to save the data submitted by the HTML form * $ _ form submitted by the POST method * $ _ GET form submitted by the get method * $ _ file upload file information * $ _ FILES = array (* 'myfile' => array (* [name] => Medical Journal-trial-background demo-5050912.zip [type] => application/zip [tmp_name] => C: \ Windows \ Temp \ phpDEB7.tmp [error] => 0 [size] => 507713 *)*) * $ _ ENV environment variable * $ _ COOKIE * $ _ SESSION * // session_start (); // $ _ SESSION ['name'] = "xue "; // VAR_DUMP ($ _ SESSION); // pri Nt_r ($ _ SERVER); // if (! Empty ($ _ POST ['sub']) // print_r ($ _ FILES ['myfile'] ['tmp _ name']); /** date and time * date (format, timestamp); * format: format * timpstamp: timestamp. the default value is the current timestamp * format: * d: 01-31 *** m: 01-12 * M of a month in a year, for example, Sep *** Y: year, 4-digit * y: 2-digit year (without the preceding 0) ** l: indicates a day in a week, which is expressed in English, for example, Monday * L: The day of a week, which is represented by the serial number, for example, if Monday is 0 and Tuesday is 1 * D, the abbreviation of the day of the week is ** other characters, such "/",". "or"-"can also be inserted into characters to add other formats. * Time format: * h: hour * H: 24 h with the first 0 x I: 00-59 * s with the first 0x12 H: with the first 0 s 00-59 * a: lowercase before noon and afternoon ** // ** creation date * 1. returns the Unix timestamp through mktime () * mktime (), that is, the number of seconds from 00:00:00, January 1, January 1, 1970 to the current period * mktime (hour, minute, second, month, day, year) * 2. strtotime () uses a string to create a date * parses any English text time into a Unix timestamp * strotime (string $ time [, int $ now]); * $ now indicates the specified time, the default value is the current time * This function is expected to accept a string containing the American English date format and try to parse it into a Unix timestamp (seconds since January 1 1970 00:00:00 GMT ), relative value The time given by the now parameter. If this parameter is not provided, the first parameter of the system's current time strtotime can be our common English time format, for example, "2000-20" or "10 September. You can also describe the time based on the parameter now, such as "+ 1 day. * ** // $ Time = mktime ("12", "20", "1", "9", "10 ", date ('Y'); // $ time = strtotime ('next month'); // echo date ("y, m, d, H: I: sa ", $ time );/**Include Require* Server-side inclusion (SSI) is used to create functions, headers, footers, or elements that can be reused on multiple pages. * Different :*RequireIf an error occurs, the running of the current script will be stopped. E_COMPILE_ERROR * is displayed *IncludeIf an error occurs, the script continues to run, and an E_WARNING warning * is given. Therefore, if you want to continue the execution and output the result to the user, useInclude. Otherwise, always useRequireReference key files to the execution stream. This helps improve application security and integrity when a key file is accidentally lost. ** // ** File operation * readfile () reads the content of a file and outputs it to the output stream. the number of bytes is returned. if the Read succeeds, the number of bytes * fopen (file name, operation method), * // readfile ("indexa. php "); // $ file = fopen ('index. php', 'r'); // echo fread ($ file, filesize ('index. php '));/**Exception handling* Try {*} catch (Exception$ Ex) {*} * custom exception class * // class MyExceptionExtendsException{// Public function errorMessage () {// echo "the error occurs in the row". $ this-> getLine (). "in". $ this-> file. ".
"; // Echo" error message: ". $ this-> getMessage (); //} // function Hander () {// throw newException("Exceptions not captured"); // set_error_handler ('hander'); // function checkNum ($ num) {// if ($ num> 1) {// throw new MyException("Value must below 1"); //} // throw newException('UncaughtExceptionOccurred '); /** filter * filter function * filter_var filter a single variable by specifying a filter * filter_var_array filter multiple variables by using the same or different prescribed filters * filter_input get an input variable and filter it * filter_input_array to obtain multiple variables, and filter them through the same or different filters ** // $ I = 123; // if (filter_var ($ I, FILTER_VALIDATE_INT )) {// echo "is an integer"; //}/** MySql operation * connection: mysql_connect ("", "", ""); * execution: mysql_query ("", $ link); ** // $ link = mysql_connect ("localhost", "root", "root"); // if ($ link) {// if (mysql_query ("create datebase my_db", $ link) {// echo "my_db created"; //} else {// echo "creation failed "; // echo mysql_error (); //} else {// echo 'link failed'; //}/**Object* 1. constructor * _ construct (): constructor and class name in php4. php5 uses _ construct. if there is no _ construct method, by default, the same method as the class name * constructor is Public by default **/classPerson {// var $ name; // The default value is public // var $ age; var $ name; var $ age; publicfunction _ construct ($ name, $ age) {echo "constructing $ name
"; $ This-> name = $ name; $ this-> age = $ age;} publicfunction _ set ($ name, $ value) {echo "calling the _ set method
"; $ This-> $ name = $ value;} publicfunction _ get ($ name) {echo" is calling the _ get method.
"; If (isset ($ this-> $ name) {return $ this-> $ name;} else {returnNULL ;}} publicfunctionsay () {echo $ this-> name. "When talking, his age is :". $ this-> age."
";} Publicfunction _ destruct () {echo" Goodbye $ this-> name "."
";}}// $ P1 = new Person (" zhang san ", 20); // $ p2 = new Person (" Li Si ", 23 ); // $ p3 = new Person ("Wang Wu", 25); // $ p2-> name = "Xue Xinhai"; // echo $ p1-> name."
"; // $ P2-> say (); // class Student extends Person {// var $ college; // public function _ construct ($ name, $ age, $ college) {// parent ::__ construct ($ name, $ age); // $ this-> college = $ college; //} // public function say () {// Person: say (); // parent: say (); // echo "his school is :". $ this-> college ,"
"; //} // $ Stu = new Student (" James ", 23," Tsinghua University "); // echo $ stu-> say (); classMyClass {public $ public = "Public"; protected $ protected = 'protected'; private $ private = 'private'; publicfunctionprintHello () {echo $ this-> public ,"
"; Echo $ this-> protected ,"
"; Echo $ this-> private ,"
";}Privatefunctionprivated () {}} classSubextendsMyClass {publicfunctionsay () {parent ::$ this-> privated () ;}// $ s = new Sub (); // echo $ s-> public; // echo $ s-> say ();/** final is only used to define classes and methods, cannot be used to define member attributes * // classes modified using final cannot be inherited from classA {publicfinalfunctionsay () {}}// the final-modified method cannot be overwritten by the quilt class. // static member method and static member attribute classST {static $ a = 3; var $ msg; const CON = 34324; publicfunction _ construct ($ msg) {$ this-> msg = $ msg;} publicfunctionsay () {echo $ this-> msg ;} publicfunction _ toString () {RETURN 'st';} publicfunction _ clone () {echo "cloning .. "; $ this-> msg =" I am a fake "; }}// _ call when the call class does not exist, call _ Call/class call {// public function _ call ($ name, $ arg) {// echo $ name, "method does not exist", "parameter: ", print_r ($ arg); //} // $ p = new Call (); // $ p-> h (" hah ", 3 ); /** abstract method * abstract function func (); * No {}, followed by brackets * as long as there is a method declaration in the class as an abstract method, this class becomes an abstract class, it must also be modified with abatract. abstract classes can contain non-abstract methods, but at least one method is an abstract method * abstract classes cannot be instantiated and can only be inherited by subclasses, the subclass must implement all abstract methods of the parent class before it can be instantiated. Otherwise, the subclass is still an abstract class **/abstractclassParents {const CONT = 3; publicabstractfunctionfunc1 (); abstractfunctionfunc2 (); publicfunctionfunc3 () {echo "Parent" ;}} classSubsextendsParents {functionfunc1 () {} functionfunc2 () {}} // $ s = new Subs (); // $ s-> func3 ();/** interface * is a special abstract class, and an abstract class is a special class. therefore, an interface is a special class. If all methods of an abstract class are abstract methods, this class is an interface * which cannot declare variables, you can declare a constant * the keyword declared by the interface is interface, not class */interfaceJK {const JJ = 244; functionfunc1 (); // The default value is public abstract functionfunc2 ();} classJimplementsJK {functionfunc1 () {} functionfunc2 () {}}$ t = new J (); $ str = serialize ($ t); unserialize ($ str ); classPerson1 {// The following is the member attribute var $ name of a person; // The name of a person var $ sex; // gender var $ age of a person; // person's age // define a constructor parameter to assign values to the attribute name $ name, gender $ sex, and age $ age. function _ construct ($ name = "", $ sex = "", $ age = "") {$ this-> name = $ name; $ this-> sex = $ sex; $ this-> age = $ age;} // The way this person can talk, say his own attribute functionsay () {echo "My name is :". $ this-> name. "Gender :". $ this-> sex. "My age is :". $ this-> age."
";}// Specify the $ name and $ age values in the returned array to be serialized, ignoring the attribute $ sexfunction _ sleep () that is not in the array () {$ arr = array ("name", "age"); // The attribute $ sex will be deleted !!! Return ($ arr);} // regenerateObjectAnd then assign $ age to 40function _ wakeup () {$ this-> age = 40 ;}$ p1 = new Person1 ("zhang san", "male ", 20); // setObjectSerializable: returns a string. The _ sleep () method is called to ignore the attribute $ sex $ p1_string = serialize ($ p1); echo $ p1_string ."
"; // Serialized strings we usually do not parse $ p2 = unserialize ($ p1_string); // deserialize to form a stringObject$ P2 re-value $ age is 40 $ p2-> say (); function _ autoload ($ classname ){Require$ Classname. '. php';} new DM ();

The above introduces the php learning 00, including some content, and hope to help those who are interested in the PHP Tutorial.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.