I would like to briefly introduce the new PHP experience.
PHP development is known for its simplicity and quickness, and it is faster to do projects than Java (3 days to get started);
But I think PHP is simple appearance, in fact, its function is very strong, I am afraid to learn more than a few years of practical project talent dare to claim it.
PHP also has a schema (but not Java strong); It also has a connection pool; but it's troublesome.
The following is a brief introduction to PHP syntax. (compared to Java; I will use the program to explain the more intuitive)
1. Embedding Method:
JSP-like <%,php can be <?php or <?, the end symbol is?>.
2. Reference file:
There are two ways to refer to a file: Require and include. (preferably with require_once and include_once; the efficiency will be slightly higher)
Require use methods such as require ("test.php");. This function is usually placed at the front of the PHP program,
Before the PHP program executes, it will read into the file specified by require and make it a part of the PHP program's Web page.
Commonly used functions, you can also use this method to introduce it into the Web page.
Include usage methods such as include ("test.php");. This function is usually placed in the processing part of the process control.
The PHP Program page reads the include file before it is read in. This way, you can simplify the process when the program executes.
3. Annotation method:
As with Java; 3 species (1:/**ABC */2:/*abc */3://ABC)
4. Variable type:
$STR = "Test";
$int 1 = 66;
$float 1 = 1.653;
$float 2 = 1.3E+5;
$array 1 = Array ("A", "B", "C", "D");
This leads to two problems, first the PHP variable begins with $, the second PHP statement ends with;
5. PHP Output Method:
Here are 3 ways to output:
Echo
printf must have parentheses; the output used to format the numbers. You can use a number as an integer, or display it in scientific notation.
Print optional parentheses
You can use the "," number to separate multiple items to display, including variables. characters. Numbers, functions, and so on.
You can use Iconv (' gb2312 ', ' utf-8 ', $response) to turn gb2312 characters into utf-8 character output.
The PHP Exit function is "Exit", and Java uses "return".
6. Learn about the System Information method for PHP:
Below you can see the system variables for PHP:
<?php
echo "<pre>";
Print_r ($GLOBALS);
?>
Example: You can find the IP of remote access
<?php echo $_server["REMOTE_ADDR"];? >
Below you can see the system Environment of PHP:
<? PHP echo phpinfo ();?>
7. Database Programming:
<?php
Database connection 3 parameters IP, user, password
$conn =mysql_connect ("127.0.0.1", "Test", "test");
Select a database named "Mysee"
mysql_select_db ("Mysee");
Execute SQL statement; Get output result $result
$result = mysql_query ("Select Channel_name, Channel_url from Live_channel where isactive=1");
$response = "{";
$i = 0;
Loop to get $result single record row value $row
while ($row = Mysql_fetch_array ($result)) {
Note: PHP characters are added with '. ' Not the same as Java (Java with ' + '); $row ["Channel_name"] the value of the field name ' Channel_name ' that can be recorded in rows
$response. = "'". $i. "': ['". $row ["Channel_name"]. "', '". $row ["Channel_url"]. "'],";
$i + +;
}
PHP Learning Experience