Home >Backend Development >PHP Tutorial >PHP study notes (1) Simple understanding of PHP, understanding of php study notes_PHP tutorial
Goal Planning:
Through the first lesson, we can understand the php environment.
1. Understanding of the environment:
2.Access method:
3. Modify the code and view it.
4. Use of variables
5. Code indentation should be hierarchical, and it is best to keep blank lines between codes
6. Variable naming:
7. Output of variables:
8. Three methods of variables:
1. Understanding of the environment:
Software download address: http://www.bkjia.com/softs/24445.html
The installation tutorial is very simple, you can search it on Baidu yourself
Directory structure after installation:
2.Access method:
Directly enter: localhost in the browser to access
3. Modify the code and view it.
We can modify index.php in the above directory www
php output html code:
<?php echo "<html>"; echo "Hello world"; echo "/html"; ?>
Suggested writing methods
<html> <?php echo "hello world";?></html>
4. Use of variables
<?php $name="junzaivip"; echo "{$name} is good"; ?>
5. Code indentation should be hierarchical, and it is best to keep blank lines between codes
6. Variable naming:
6.1. Try not to use Chinese
6.2. Try not to start with a number
6.3. Try not to use meaningless letters
6.4. Variable names are case-sensitive, function names are not case-sensitive, and class names are not case-sensitive either. Simply put variable names and functions in lowercase.
6.5. Definition of variables The definition must be added with $
7. Output of variables:
echo $name;
8. Three methods of variables:
echo($name); //Output variable
var_dump($name);//Output the array and print the type and length
print_r($name);//output array
example:
<?php $arr=array("胡军","垒成","大哥"); print_r($arr); var_dump($arr); ?>
Displayed as follows
Through the above display, we can see that the display is very ugly and does not require reading, so the formatted output solution is:
<?php $arr=array("胡军","垒成","大哥"); echo "<pre class="brush:php;toolbar:false">"; print_r($arr); echo ""; ?>
The results are displayed as follows:
Tips:
When encoding in Utf-8, a Chinese character is 3 characters
When gbk is encoded, one Chinese character is 2 characters
Try using templates. All interface designs are for a static web page. All the content you need in this static web page is represented by PHP variables (or other special formats specified by you). Design When laying out, such static web pages are operated.
The website does not directly display the web page to the outside. All the content of the web page is obtained from the database by the PHP program, and the variables in the web page template are replaced and output.
For example, your homepage template can be named index.htm, and index.php is actually used to display the homepage. The PHP process is as follows:
bf021d16dda100f2ec8759e610233558
Your conn.php should be a connection library file for mysql database. With this file, you can connect to the database, right? But then why do you need to echo $sql? You should use mysql_query. $result=mysql_query( $sql,$conn)or die(mysql_error());