1. Introduction of related content
1> Internet Development
-
Internet: Traditional Internet, mobile internet
-
Internet development: Front-end development (front office), background development (backend, service side)
-
Front-end development: Visual display (user interface), user interaction, acquisition of input information
-
Background development: Manage and process data, develop interfaces to clients, control output
2> Client Server Mode (c/s)
-
Client: Initiate communication proactively (initiating a request) such as: Browser, mobile client, etc.
-
Server: passively waits for communication (response request) such as Web server, FTP server, mail server, etc.
3> WEB Server Development
Web server: In a networked environment, a response service is provided for the client initiating the request, primarily to handle HTTP requests.
2. Webserver Environment construction
1> Environment Construction
-
Apache:web Server Software, supporting the vast majority of computer operating systems, is one of the most popular Web server software. Mac system comes with Apache.
-
PHP: For webserver development of the scripting language, cross-platform, support the vast majority of databases and operating systems, mixed with C, Java language syntax, open source code.
-
MySQL: Relational database management system, small size, fast speed, widely used in small and medium-sized web sites.
2> Xampp and Coda
- XAMPP is a software package, integrated with the Apache+php+mysql installation environment, one-click installation, convenient and quick.
- Coda: A Web programming tool for Mac computers with multi-lingual support (HTML, PHP, JavaScript, CSS, etc.)
3> Web Server Workflow
3. Web page Development
1> principle
2> Local server path
3> Accessing server files
URL format: protocol://domain/path/query
http://127.0.0.1
Accessing the local Web server root directory, loading the index file contents by default
HTTP://127.0.0.1/file path (including file name and suffix)
Access a file in the root directory of the local Web server, pictures, PHP, html
4. PHP basic Syntax
1> PHP Tags
<? PHP Echo ("Hello Lanou");// output function "<br/>" // line wrap echo The output function can be ?> without parentheses
Reference Study website: http://www.runoob.com/php/php-tutorial.html
2> variable
Variable definition
Variables begin with $, followed by variable names
Variable letters, numbers, underscores, not starting with numbers
Variable names are case-sensitive
Defining Automatic type Variables
$int _value = ten; $float _value = 1.5; $name = "Hello Lanou";
Get variable Type returns string
GetType ($name);
3> String
Connection string
$name = ' IPhone '; $str = ' 5 '; $name $name. $str ; Echo ($name);
4> If branch
// comparison of two variables, output maximum value $a = 3; $b = 5; if ($a>$b) { echo($a); } Else { echo($b); }
5> for Loop
// output 1~10 All the numbers between for ($i = 1; $i<=10; $i+ +) {echo($i. ') <br> ');}
6> Random Number
Generate a random number between a~b rand (A, B)
// generates a random number between 20~50 and outputs $num Rand (a); Echo $num;
7> Array
In PHP, create an array using the array () function
In PHP, there are three types of arrays:
Numeric array-an array with a numeric ID key (similar to Nsarray)
Associative array-An array with the specified key, with each key associated with a value (similar to nsdictionary)
Multidimensional arrays-An array that contains one or more arrays
$array 1 Array (); // Empty Array $array 2 Array (98, (); // array of values $array 3 Array ("Name" = "Lishuai", "Age"=>40); Associative array, key = = value Print_r ($array 3); Output array Contents
8> array of values
The count () function is used to return the number of array elements
$count Count ($array); Echo $count;
Adding an array element
$array [] =; // the last element in the array
Accessing array elements
$array [digital ID key]
Iterating through an array of values
foreach (array as $value) {
Echo ($value. " <br/> ");
}
$array Array (a); foreach ($arrayas$value) { echo($value. ") <br/> "); }
9> Associative arrays
$person Array ("Name" = "Yihuiyun", "Age" = "Print_r") ($person); Output
Output result Array ([name] = Yihuiyun [age] + 18)
$person Array ("Name" = "Yihuiyun", "age" = "+")//count () function to return the number of array elements $count = count ($person$count;//Add key-value pairs $person["sex"] = "female "; Get values by key//$person[key]
Traversing associative arrays
foreach (array as $key = = $value) {
Echo ($key. ":". $value. " <br/> ");
}
$person Array ("Name" = "Yihuiyun", "age" = "+"); foreach ($person$key=$value) { echo ($key. ":". $value. " <br/> ");}
10> JSON conversion
// Array goto JSON string $json = Json_encode ($array); // JSON string to PHP object $array = Json_decode ($json);
5. PHP Implementation API Interface development (GET)
1> Overview
In PHP, the predefined $_get variables are used to collect values from the form method= "GET".
Information sent from a form with a GET method is visible to anyone (displayed in the browser's address bar) and has a limit on the amount of information sent.
A url:http://127.0.0.1/get.php?username=lanou&password=123 of the GET pass value
Parse: http://127.0.0.1/get.php parameter name 1= value 1& parameter name 2= value 2
Parameter names are usually set by the background, and the front end is filled in with the interface documentation
The PHP file receives the data code:
// get Data key must be consistent with parameter name $name $_get ["username"]; $password $_get ["Password"];
2> iOS Network programming
Code:
6. PHP Implementation API Interface development (POST)
1> Overview
The predefined $_post variables are used to collect values from the form method= "POST".
Information sent from a form with a POST method is not visible to anyone (not displayed in the browser's address bar), and there is no limit to the amount of information sent
http://127.0.0.1/post.php
The URL does not need to carry parameters, through the body upload parameters
The PHP file receives the data code:
// get Data key must be consistent with parameter name $name $_post ["username"]; $password $_post ["Password"];
PHP First Experience