PHP Code writing

Source: Internet
Author: User

In the php file, write to the header (' Content-type:text/html;charset = Uft-8 ');
<!--==============================--
<?php
Header (' Content-type:text/html;charset=utf-8 ');
echo "Hello World Chinese";
function sum ($a, $b) {
Return ' <div style = ' color:red ' > '. ($a + $b). ' </div> ';
}
(Echosum);
?>
<!--=================================--
Put the written php file in the WWW directory to display the loaded.
Local file preview, enter the 127.0.0.1/php file in the browser, you can load, or enter the localhost:80/php file in the browser;
Modify the port under Wamp run left click on the httpd:conf query listen port in Apache to modify. With # are comments. After the modification is complete, you need to restart all services (restart the program).

Web page Generation principle:
Describe the process of request and response, drawing the form.

PHP is written and run.
Make a text document with the extension changed to PHP. , write the PHP code in the file, put the file in the Apache www directory, run through the browser.
Attention:
1. Open the browser, enter http://127.0.0.1 in the Address bar or enter http://localhost to access the files under the WWW directory of Apache.
2, if you want to let others visit our site, you can let him on his computer through the browser to access HTTP.//My Computer's IP
3. Method of viewing IP: Win+r,cmd,ipconfig
4,apache in the httpd.conf file to make configuration for others to access, ctrl+f, enter 127.0.0.1. Find to change it to all.
5, you can modify the directory of WWW in Apache to point to.
6, you can run multiple sites.
7,wamp red indicates error, yellow indicates some services have problems, green indicates normal.
The usual reason for the yellow is that 80 ports are occupied and the port is changed under httpd.conf.
In Listen, Document.root here to modify.

In PHP echo and print are output, echo can output multiple strings with a comma interval, print can only output a string, echo output faster than print, the print return value is 1,echo no return value.
Variable: $name = 123;$ is used to represent a declared variable. Data types can be strings, numeric values, arrays, booleans, numeric values, and so on.
Constant Const:const a = 1; or define (' a ', ' 2 ');
Const-defined constants are locked and locked within the heap and cannot be modified.
If statement, the condition in the switch statement is not able to write directly similar to a non-null or True condition. Must be a direct Boolean value.
Loop: For Loop, foreach ($array as $a value), while (condition), do{}while (condition);
Arrays: Array (' A ', ' B ', ' C ');//do not want to directly write the literal as JS.
Quantity: Count ($array);

Sort: Ascending sort ($array), sorted exactly by size, without the so-called "5" > "10" Problems.

Descending Rsort ($array);//Sort directly on an array.

Var_dump ($array) can see the data structure.
Associative arrays: JSON
$object = Array (
"Name" = "Zhang San Fung",
"Age" = 100
);
foreach ($object as $key = val)
{
Echo $val;

}
Json:
Json_decode (); JSON string converted to JSON object
Json_encode (); JSON object to JSON string

PHP Writing and running
function: $a = 1;
function fn ()
{
Global $a;
echo $a;
echo $GLOBALS [' a '];
}
FN ();

Within a function, the global variable A cannot be directly obtained, and must be described in global.

Form:
<form method= "Get" >
<input type= "text" Name= "a" >
</form>
Php:
$_get["]
$_post["]
$_request["can accept both get data, post data, and cookies.
Gets the input for the text field, based on the Name property of the form's text field.

Session Tracking Technique session:
1,php page
Session_Start ();
$_session[' a ']=1;;
2,php page
Session_Start ();
Echo $_session[' a '];

Session Tracking Technology Cookie:

1.php page
Setcookie ("AA", "123", Time () +5);//Expires after 5 seconds of the current

2.php page
echo $_cookie["AA"];

File Introduction:
<?php
Echo ' hello<br> ';

Include ' 2.php ';//When this 2.php does not exist, the following code can be executed.

Require ' 2.php ';//When this 2.php does not exist, the following code is no longer executed.

echo ' <br> hello ';
?>

IP Address:

Client ip:$_server[' REMOTE_ADDR ']

Server-side ip:$_server[' SERVER_ADDR ']


Computer IP Address Viewing method:

Window:ipconfig

Mac:ifconfig

Website Service

What the function of a file is, it can say what service it provides.

Access to this file by URL means that we have used the service.

Web-service is a standard inter-system interface protocol that encapsulates and implements interface interoperability through a service approach.
Service is not a virtual thing, but an entity, it is related to the customer, and this entity through a well-defined message exchange to provide users with some kind of ability.

PHP Code writing

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.