17. php

Source: Internet
Author: User
Tags array definition http post php and mysql type null

Php1. Three components of Web services

==apache, PHP, mysql==

Apache server. (port number definition, ==http protocol = =, open and close)

?? An open source HTTP server, which can run on most computer operating systems, is one of the most popular Web server-side software because of its widespread use of multiple platforms and security.
?? To put it simply: Apache is a program that provides Web services for executing Web programs and displaying Web pages on the server. Apache itself does not have PHP and MySQL to provide services.

The default port for apache== is 80==: ==https://localhost:80/==

Apache's core services are httpd, and then the services are loaded in turn.
Apache can also listen to multiple ports, modify the configuration in the httpd.conf file, we modify the port.

2.http protocol
  1. The HTTP protocol is an abbreviation for the Hyper Text Transfer Protocol (Hypertext Transfer Protocol), which is used to transfer hypertext to the local browser from the World Wide Web (www:world Wide Web) server.
  2. HTTP is a TCP/IP communication protocol that transmits data (HTML files, image files, query results, and so on).

Web Services working schematic diagram

3.PHP Marking

1. When parsing a file, PHP will look for the start and end tags, as well as = =, which tells PHP to start and stop parsing the code between the two.
This parsing allows PHP to be embedded in a variety of different documents, and any part outside the start and end tags will be ignored by the PHP parser.

2. If the file content is pure PHP code, it is best to remove the PHP end tag at the end of the file.

4. Set character Sets:

==header ("Content-type:text/html;charset=utf-8"); = =

5.PHP supports 9 types of raw data

Four types of scalar:
1) Boolean (Boolean, case-insensitive)
2) Integer (integral type)

<?php$a = 1234; // 十进制数$a = -123; // 负数$a = 0123; // 八进制数 (等于十进制 83)$a = 0x1A; // 十六进制数 (等于十进制 26)$a = 0b11111111; // 二进制数字 (等于十进制 255)?>

3) Float (floating point type, also called double)
4) string (string)

Three types of composite:

1) Array (array)
2) object (object)
3) callable (callable)

Two special types:
1) Resource (resources)

A) resource resource is a special variable that holds a reference to an external resource. Resources are created and used through specialized functions.
2) NULL (no type)

A) A special null value indicates that a variable has no value. The only possible value for a null type is NULL.

b) A variable is considered null in the following cases:

I. Assigned value is NULL

II. Has not been assigned a value.
III. Delete unset ()

When currently converted to Boolean, the following values are considered false:

I. The Boolean value false itself

Ii. integer value 0 (0)

Iii. floating-point value 0.0 (0)

Iv. empty string, and string "0"

V. Arrays that do not include any elements

VI. special type null (including variables that have not been assigned)

If you want to see the value and type of an expression, use the Var_dump () function.

<?php    header("content-type:text/html;charset=utf-8");

==echo== output: Multiple data can be output at one time, separated by commas, no return value, slightly higher performance than print

echo "我是PHP","我喜欢PHP","<br>";

Defining arrays

$arr = [1,2,3,‘a‘,true];    unset($arr[0]);

==var_dump () output = = Output results Detailed information

    var_dump($arr);    print_r($arr); //输出数组的简单信息    echo "<br>";

//. : Connector
==print== output: Only one data can be output at a time with a return value of 1

print ‘我也是PHP‘."我喜欢PHP".$arr[0];
5.==gettype== and ==is_style==

Use the GetType () function if you just want a readable type of expression for debugging purposes. To verify a type, do not use GetType () and use the Is_type function
GetType (), judging is a type, return type.
Is_type (), judging whether it is a certain type, returns 1 or 0.

<?php    $str = ‘hello‘;    echo gettype($str);//string    echo is_string($str);//1?>
6. Form (get POST request) 1. $_get An array of variables passed to the current script through the URL parameter.
<?phpecho ‘Hello ‘ . htmlspecialchars($_GET["name"]) . ‘!‘;?>
2. $_post: When the HTTP POST request Content-type is application/x-www-form-urlencoded or multipart/form-data, the variable is passed into the current script as an associative array.
<?phpecho ‘Hello ‘ . htmlspecialchars($_POST["name"]) . ‘!‘;?>
3. (iii) $_request: By default, an array of $_get,$_post and $_cookie is included.

Extension: Htmlspecialchars: Converting special characters to HTML entities

<?php$new = htmlspecialchars("<a href=‘test‘>Test</a>", ENT_QUOTES);echo $new; // &lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt;?>
7. Array into json1. Define Array ()

You can use the array () function to create a new array. It accepts any number of key (key) = = VALUES (value) pairs separated by commas.
Array (Key=>value,......)

The = = key can be a whole number integer or string string==
Values (value) can be any type of value

$array = [    "foo" => "bar",    "bar" => "foo",];?>
2.Key will have the following casts:

1) A string containing a valid integer value is converted to an integral type. For example: The key name "8" will actually be stored as 8. However, "08" does not cast because it is not a valid decimal value.
2) floating-point numbers are also converted to integers, meaning that their fractional parts are removed. For example: Key name 8.7 will actually be stored as 8.
3) The Boolean value is also converted to an integer type. That is, the key name true is actually stored as 1 and the key name false is stored as 0.
4) NULL is converted to an empty string, that is, the key name null is actually stored as "".
5) Arrays and objects cannot be used as key names. Insisting on doing so will result in a warning: illegal offset type.
6) If more than one cell in the array definition uses the same key name, only the last one is used, and the previous is overwritten.

3. Iterating through an array

1) Foreach (array as $value) {}
2) Foreach (array as $key = = $value) {}

4. Convert Arrays to JSON
    1. ==json_encode==: A JSON-encoded variable that returns a string containing a representation of the value in JSON form.
<?php$arr = array (‘a‘=>1,‘b‘=>2,‘c‘=>3,‘d‘=>4,‘e‘=>5);echo json_encode($arr);?>输出 :{“a”:1,”b”:2,”c”:3,”d”:4,”e”:5}
8.php global Variable 1. Variables in PHP are represented by a dollar sign followed by a variable name. Variable names are case-sensitive. 2. The variable name follows the same rules as other tags in PHP. A valid variable name begins with a letter or underscore, followed by any number of letters, numbers, or underscores. 3. Global Variables: Globals
<?php$a = 1;$b = 2;function Sum(){    global $a, $b;    $b = $a + $b;}Sum();echo $b;?>

A. The following values are considered false when the current conversion is to Boolean:

I. The Boolean value false itself

Ii. integer value 0 (0)

Iii. floating-point value 0.0 (0)

Iv. empty string, and string "0"

V. Arrays that do not include any elements

VI. special type null (including variables that have not been assigned)

B. All other values are considered true (including any resources and Nan);

C. <?php

var_dump((bool) "");        // bool(false)var_dump((bool) 1);         // bool(true)var_dump((bool) -2);        // bool(true)var_dump((bool) "foo");     // bool(true)var_dump((bool) 2.3e5);     // bool(true)var_dump((bool) array(12)); // bool(true)var_dump((bool) array());   // bool(false)var_dump((bool) "false");   // bool(true)?>

17. php

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.