PHP notes--java programmer to read PHP program

Source: Internet
Author: User
Tags change settings html form php script alphanumeric characters

PHP notes--java programmer to read PHP program

    1. PHP is a server-side scripting language with a loosely typed language.
    2. <?php?> XML style

<script language= "PHP" ></script> scripting style

<? ?> Short Style

<%%> ASP Style

to end;

    1. Comments:

A)//

b) #

c)/* */

    1. Variables are containers that store data and are case-sensitive. When the variable is very long, use the delimiter <<<.

$k =<<<str

...

Str

Because PHP is a loosely typed language, variables do not have specific type keywords at the time of declaration.

Unify with $ start + variable name

1. Must start with a letter or _

2. Can only contain alphanumeric characters and underscores

3. Sensitive to case

    1. Variables can be declared anywhere in the PHP script.
    2. Referenced/used Scripts-scope

A) local (local)

b) Global (global)

c) static (static)

Variables declared outside the function have global scope and can only be accessed outside of the function.

Variables declared inside a function have a local scope and can only be accessed within a function.

Calling the global variable inside the function requires ① to be declared internally with global keywords, and ② $GLOBAL [index] stores all global variables, which can be obtained through the hyper-global variable $global[index].

    1. $GLOBAL [index] This array is accessible within the function and can be used to update global variables directly.
    2. Typically, when a function finishes executing, all variables are deleted. If you do not need to delete, you need to use the static when you first declare
    3. A constant has no $, and its value cannot be changed in the script. By define ("Name of Constant", "constant value", "constant name is case sensitive"), true (same case) insensitive, false sensitive. Define constants in the class with the const keyword.

A constant that changes according to the position used, and becomes the magic constant.

1) __file__ current folder

2) __line__ Current number of rows

3) __function__ Current function name

4) __class__ Current class name

5) __method__ The method name of the current object

    1. Print: Echo is capable of outputting more than one string.

Print can only output one string and always returns 1.

    1. String length strlen (); Retrieves the character or text specified within the string Strpos (); string connection with ".", "." Followed by a number must be a space.
    2. Super Global variables:

A) $GLOBALS reference all variables in the global scope.

b) $_server save information about the header, path, and location of the script.

c) $_request is used to collect data submitted by HTML forms.

D) $_post is widely used to collect form data after submitting an HTML form for method= "POST", as well as for passing variables.

e) $_get is used to collect the form data after the submission of the HTML form (method= "GET"), or to collect the data sent in the URL.

f) $_files upload files from the client computer to the remote server.

g) $_env Gets the server-side environment parameters. (Variables_order=epgcs)

h) $_cookie is used to retrieve the value of the COOKIE.

i) $_session is used to store information about a user's session, or to change settings for a user session.

    1. The Include/require statement gets all the text/code/tags that exist in the specified file and is copied to the file using the Include/require statement.

A) require (static loading), when an error occurs, a fatal error is generated and the script is stopped.

b) include (dynamic load), when an error occurs, only generate a warning, the script will continue to execute.

c) Require_once/include_once the same page is included only once.

    1. Array processing: the array name [' Key Name '] to initialize the array, or you can create an array by using the array () function.

COUNT () returns the length of the array.

Array traversal: The Foreach Loop, with Count () to get the length of the array and loop through the for;list () language structure, only for the default numeric index; each () returns a key-value pair.

while (list ($key, $value) =each ($array)) {

}

foreach ($array as $key = = $value) {

}

    1. Class objects in PHP are declared with the class keyword, the properties of the class are scoped, the scope can be modified with Var, and the member method differs from the function in that it can be decorated with a keyword. Constructor __constract, destructor __destruct
    2. "::" scope operator, which can invoke constants, variables, and methods in a class without instantiation;

"= +" array member access symbol;

Object member access symbols;

"=&" references (aliases);

"=" assignment.

    1. $ Variable name = new class name ([parameter]); instantiation;

$ variable Name, member property = value; Assign a value to a property;

$ variable name, member property; Gets the attribute value;

$ variable-name-member method; method of Use;

    1. MySQL: Typically packaged in conn.php, then use require to the desired page.

1) $conn = Mysql_pconnect ("localhost", "root", "") or Die (Mysql_error ());

2) mysql_select_db ("Database name", $conn);//Connect to the specified database.

3) mysql_query ("Set names UTF8");

4) $sql = "";

5) $resultSet = mysql_query ($sql) or Die ("Invalid query:". mysql_error);//returns the SQL statement result set;

6) while ($v = Mysql_fetch_array ($resultSet)) {

7) echo "Field name:". $v [' title '];

8)}

9) Mysql_free_result ($resultSet);//close result set;

Mysql_close ($conn);//close connection

I have to keep on learning to know what this place is going to write.

PHP notes--java programmer to read PHP program

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.