PHP notes--java programmer to read PHP program

Source: Internet
Author: User
Tags change settings alphanumeric characters


1. PHP is a server-side scripting language with a loosely typed language.

2. ?> XML style

scripting style

?> short style

<% %> ASP style

in ; end;

3. notes:

a) //

b) #

c) /* */

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

$k =<<<>< span=""><>

...

Str

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

Unified Use $ Start + Variable name

1. must have letters or _ Start

2. can only contain alphanumeric characters and underscores

3. sensitive to case

5. variables can be PHP The script is declared at any location.

6. is referenced / script to use-scope

a) Local ( partial )

b) Global ( globally )

c) static ( statically )

variables declared outside of a function have Global scope, which can only be accessed outside of the function.

variables declared inside a function have Local Scope , which can only be accessed within a function.

function Internal Call Global variables need to be ① internally with Global keywords to declare; ② $GLOBAL [index] All global variables can be stored in a hyper-global variable $GLOBAL [index] obtained in the.

7. $GLOBAL [index] This array is accessible within the function and can be used to update global variables directly.

8. 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

9. constant None $, The value cannot be changed in the script. by define (" name of the 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

. Print: echo capable of outputting more than one string.

Print Only One string can be output, and always returns 1.

One by one . string Length strlen (); retrieves the specified character or text within a string Strpos (); string connection with " . " , " . "followed by a number must be a space.

. Super Global variables:

a) $GLOBALS references all variables in the global scope.

b) $_server holds 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 submitted method= "POST" The form data after the HTML form is also commonly used with transitive variables.

e) $_get is used to collect the submitted HTML form (method= "GET" ) After the form data, you can also collect The data sent in the URL.

f) $_files uploads 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.

. Include/require statement gets all the text that exists in the specified file / Code / tag, and copy it to the Include/require statement in the file.

a) require ( static loading ), when an error occurs, generates a fatal error and stops the script.

b) include ( dynamic load ),When an error occurs, only a warning is generated, and the script continues execution.

c) require_once/include_once The same page is included only once.

. Array Processing: $ Array name [' Key name '] to initialize the array, or you can Array () function to create an array.

count () Returns the length of the array.

Array Traversal: foreach cycle, with count () get the length of the array and then use for;list () language structure loops, only for default numeric indexes ; each () a key-value pair is returned.

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

}

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

}

A . PHP in the class object with class keyword to declare that the properties of a class also have scope, and do not specify scopes that can be used var The difference between a member method and a function is that it can be decorated with a keyword. Constructor __constract, destructor __destruct

. " :: " a scope operator that can invoke constants, variables, and methods in a class without instantiation;

" = " array member access symbols;

" - " object member access symbols;

" =& " references (aliases);

" = " assigned value.

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

$ Variable name - member Properties = value ; // Assign a value to the attribute;

$ Variable name - member Properties ; // get attribute value;

$ Variable name - member Methods ; // use method;

. MySQL : General use conn.php package, and 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);// return 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;

Ten) mysql_close ($conn);// close Connection

Copy to Google Translate Translation Results

The above describes the PHP note--java programmer to understand the PHP program, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    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.