Home >Backend Development >PHP Tutorial >PHP notes - Java programmers understand PHP programs, phpjava programmers understand_PHP tutorial
1. php is a A server-side scripting language, a loosely typed language.
2. ?> >
Script style >
Short style <% >ASPStyle
ends with ;; 3.
Note:a)
// b)
# c)
/* */
4. Variables are containers for storing data and are case-sensitive. When the variable is very long, use the delimiter <<<.
$k=<<
…
str;
I think PHP is a loosely typed language, so there is no specific type when variables are declared. Type keyword.
$ Variable name
1. must be letters or _begins
2. can only contain alphanumeric characters and underscores
3.
5. PHP is declared anywhere in the script.
6. Quoted/ Script used - scope
a) local(local ) b) global(global ) c) static(static ) Variables declared outside the function have global scope and can only be outside the function for a visit. Variables declared inside a function have local scope and can only be used within the function access. Function internal callglobalVariables need to be used internally global keywords are declared; ②$GLOBAL[index] All global variables are stored in , which can be obtained through the super global variable $GLOBAL[index]. 7. $GLOBAL[index]This array is accessible within the function and can be used to directly update global variables. 8. Usually, when the function completes execution, all variables are deleted. If you do not need to delete it, you need to use static 9. Constant None$ , cannot be changed in script. Pass define("The name of the constant","The value of the constant”,”Whether the constant name is case-sensitive”);true(Same case)Insensitive, falseSensitive. To define constants in a class, use the const keyword. A constant that changes depending on where it is used becomes a magic constant. 1) __FILE__ Current folder 2) __LINE__ Current line number 3) __FUNCTION__ Current function name 4) __CLASS__ Current class name 5) __METHOD__ The method name of the current object 10. Print: echo can output more than one string. print can only output a string and always returns 1. 11. strlen();Retrieve the specified characters or text within the stringstrpos(); String concatenation uses ".", “.” must be followed by a space.
12. Super global variable:
a) $GLOBALS refers to all variables in the global scope.
b) $_SERVER Saves information about headers, paths and script locations.
c) $_REQUEST is used to collect HTML form submission data.
d) $_POST 🎜>Widely used to collect submissionsmethod=”post”The form data after the HTML form is also commonly used to pass variables.
e) $_GET 🎜> is used to collect submissionsHTML form (method="get") can also collect form data after URL< Data sent in 🎜>.
f) 🎜>Upload files from client computer to remote server.
g) Get the server-side environment parameters. (variables_order=EPGCS)
<<> H) $ _ cookie is used to retrieve the value of cookie.
i) is used to store information about a user session, or to change the settings of a user session. 13. The statement will get all the text that exists in the specified file /Code / tag and copy it to the file using the include/require statement.
a) require(static Loading ), when an error occurs, a fatal error will be generated and the script will stop.
b) include(dynamic Load ). When an error occurs, only a warning will be generated and the script will continue to execute.
c) require_once/include_once Contain the same page only once.
14. Array processing: $Array name['Key name'] to initialize the array; you can also use Array() Function to create an array.
count()Returns the length of the array.
Array traversal: foreach loop, use count()Get the length of the array and then use for;list()Language structure loop, only used for default numeric index ;each() returns key-value pairs.
while(list($key,$value)=each($array)){
}
foreach($array as $key => $value){
}
15. PHPMedium Objects are declared using the class keywords. Class attributes also have scopes. If you do not specify a scope, you can use var is modified. The difference between member methods and functions is that they can be modified with keywords. Constructor__contract,Destructor__destruct
16. ” Scope operator, can be used in Call constants, variables and methods in a class without instantiation;
"=>" Array member access symbol;
"->" Object member access symbol; "=&" Quote (alias); "=" Assignment. 17. $Variable name = new Class name([Parameters]); 🎜> instantiation;
$ Variable name->Member attribute = value; //Assign a value to the attribute;
$ Variable name->Member attributes; >Get attribute value;
$Variable name-> Member methods; >How to use;
18. mysql: General Use conn.php to encapsulate it, then use requireGo to the required page.
1) $conn = mysql_pconnect("localhost","root" ,"") or die(mysql_error());
mysql_select_db(“ Database name”,$conn);// Connect to the specified database.
3) mysql_query("set names utf8");
$sql = “”;
$resultSet = mysql_query($sql) or die (“Invalid query : ".mysql_error);//Returnsql statement result set;
6) while($v = mysql_fetch_array($resultSet)){
echo " Field name: ".$v['title']; 8) } 9) mysql_free_result($resultSet);//Close the result set; 10) mysql_close($conn);//Close connection