PHP Preparation and Foundation

Source: Internet
Author: User
Tags constant definition php development environment
PHP Build and Basics

The 1.php development environment is built:

1. Build under Linux

linux+apache+mysql+php

2. Setting up under Window

Apache+php+mysql+phpmyadmin

View Port: Cmd-->netstat-an

Installation method:

1. Kit Installation:

Common kit: Appserv,wmap,phpstudy

Apache HTTP Server:apache Web server

MySQL Database:mysql Database

PHP Hypertext preprocessor:php Core

PhpMyAdmin: Graphical tool for managing MySQL database-->next

?

Server Name:localhost

Administrator ' s email address:53032104@qq.com--> admin Email

Apache HTTP port:8000--> Port number-->next

?

Please enter the Root password for MySQL server-->root user password

Enter Root Password:root

Re-enter Root Password:root

MySQL Server Setting

Characher Sets and Collations:utf-8 unicode--> Specify database encoding, recommended UTF-8

?

2. Custom Installation:

1.apache

Test: http://localhost

2.php Core Package: (PHP official website: http://www.php.net) decompression can be

Using apache+php under Windows, select VC6 version

Using iis+php under Windows, select VS9 version

?

Apache and PHP Integration:

1. In the D:\phpStudy\Apache2\conf\httpd.conf file, add 130 rows or so:

LoadModule php5_module "D:/phpstudy/php5/php5apache2_4.dll" #php安装目录下的php5apache2 -4.dll

Phpinidir "d:/phpstudy/php5/" #php安装目录

AddType application/x-httpd-php. php. phtml #指定若文件为. php or. phtml, will be handled by PHP

?

2. Under the PHP installation directory: Rename the php.ini-development file to PHP.ini

3. In php.ini search Extension_dir = "./", open this line, specify the path of the ext file under the PHP installation directory

Extension-dir = "D:/phpstudy/php5/ext"

?

Test:

Create a new test.php file in the Htdocs directory under the Apache installation directory with the following code

Phpinfo ();

?>

Restart apache:http://localhost/test.php

?

3.MySQL database: (MySQL website: http://www.mysql.com)

Test:

1. Write a PHP code to test for success

$conn = mysql_connect ("localhost", "root", "root");

if ($conn) {

echo "Connect MySQL database ok!";

}else{

echo "Connect MySQL database not ok!";

}

?>

2. Install a phpmyadmin to test availability (manage MySQL)

Installation method: Unzip to the Htdocs folder, enter the index.php file under this directory

Access mode: http://localhost:8000/phpMyAdmin/index.php

?

2.http://www.comsenz.com

1. Download Discus Forum Code

2. Unzip to the Htdocs folder

3. Modify the file config.inc.php:

$dbhost = ' localhost ';//Database server

$dbuser = ' root ';//database user name

$DBPW = ' root ';//Database Password

$dbname = ' discuz ';//Database name

$pconnect = 0;//Database Persistent connection 0 = off, 1 = Open

?

$database = ' mysql ';//Forum database type, do not modify

$dbcharset = ' UTF8 ';//MySQL character set, optional ' GBK ', ' big5 ', ' utf8 ', ' latin1 ', left blank for set by forum character set

?

$charset = ' utf-8 ';//forum page default character set, optional ' GBK ', ' Big5 ', ' utf-8 '

$headercharset = 0;//Force Forum page Use the default character set, you can avoid some server space page garbled, generally do not need to open. 0= off 1 = Open

?

$forumfounders = ' admin ';//Forum founder UID, can support multiple founders, between using "," delimited.

Note: You need to set php.ini in: Short_open_tag = On

4. Access the install.php file under Discus for database installation

After the installation is complete:

Ucenter's visit Address: http://localhost/upload/ucenter

Ucenter founder Password: admin

Discuz! 's visit Address: Http://localhost/upload/bbs

Administrator Access URL: http://localhost/upload/bbs/admincp.php

Admin Account: admin Admin Password: admin

Ucenter Home's visit URL: http://localhost/upload/home

Administrator Access URL: http://localhost/upload/home/admincp.php

Admin Account: admin Admin Password: admin

?

?

To configure a Web site in an Apache server:

1. To create a Web site in the Apache server, you need to enable the httpd-vhosts.conf file to be added:

Note: Make sure that the DNS Client service is in a startup state

2. The configured host must be registered with the DNS server or Windows system to be externally accessible

?

Ideas:

1. Differentiate different virtual hosts by port

One: Follow the method of binding a site to prepare

1. Development site D:/myblog

2. Configure our httpd.conf file?

Enable httpd-vhosts.conf

Note DocumentRoot "D:/apache/htdocs"

3. Locate the file conf/extra/http-vhosts.conf file

Template:

DocumentRoot "D:/myblog"

DirectoryIndex index.php index.html

Options FollowSymLinks

AllowOverride None

Order Allow,deny

Allow from all

4. Add an object relationship between the IP and the domain name in the Hosts file

Path: C:\Windows\System32\drivers\etc\hosts

Added: 127.0.0.1www.moluo.com

5. Test: Access http://www.moluo.com:80

?

Two. Add a new domain name to the IP binding

1. Development of a new website

2. Configure httpd-vhosts.conf to add a new virtual host

DocumentRoot "D:/myblog2"

DirectoryIndex index.php index.html

Options FollowSymLinks

AllowOverride None

Order Allow,deny

Allow from all

3. Allow Apache to listen on port 82 in the httpd.conf file

Listen 82

4. Add an object relationship between the IP and the domain name in the Hosts file

Path: C:\Windows\System32\drivers\etc\hosts

Added: 127.0.0.1www.fengpeng.com

5. Test: Access http://www.fengpeng.com:82

?

2. Differentiate different virtual hosts by servername

1. Development site D:/myblog

2. Add the configuration in the httpd-vhosts.conf file

DocumentRoot "D:/myblog"

ServerName www.moluo.com

DirectoryIndex index.php index.html

Options FollowSymLinks

AllowOverride None

Order Allow,deny

Allow from all

DocumentRoot "D:/myblog2"

ServerName www.fengpeng.com

DirectoryIndex index.php index.html

Options FollowSymLinks

AllowOverride None

Order Allow,deny

Allow from all

3. Add an object relationship between the IP and the domain name in the Hosts file

Path: C:\Windows\System32\drivers\etc\hosts

Added: 127.0.0.1www.moluo.com

4. Test: Access http://www.moluo.com

Visit http://www.fengpeng.com

?

What the Web site means: A collection of multiple Web resources, including PHP/HTML/JS/CSS

The basic syntax of PHP is introduced:

If you just want to display a variable:

PHP code Comments:

Single-line comment?

/* Multiline Comment */

Quotation marks difference:

Single quotes: output with intact data

Double quotes: Parsing data special characters, variables, etc.!

Constant definition:

Note: 1. Name: Uppercase, Underline

2. Does not require a $ start

3. Once assigned, cannot be changed

1.define ("Tax_rate", "0.02")

2.const tax_rate = 0.02;

Pyramid instance:

$n = 10;

for ($x =1; $x <= $n; $x + +) {

for ($z =1; $z <= $n-$x; $z + +) {

echo "";

}

for ($y =1; $y <= ($x-1) *2+1; $y + +) {

if ($x ==1| | $x = = $n) {

Echo ' * ';

}else{

if ($y ==1| | $y = = ($x-1) *2+1) {

Echo ' * ';

}else{

echo "";

}

}

}

Echo '
';

}

?>

?

Function Description: (Commonly used: require_once ())

Basic format:

function method ($a, $b) {

echo $a + $b;

}

?>

?

The a.php page invokes the function defined by b.php and can use the following directives

Require require_once? include Incliude_once

Example:

1.require ' b.php ';

2.require (' b.php ');

3. $filename = ' b.php ';

? require $filename;

?>

Require and require_once differences:

The former encounters the include file, the latter will determine whether it has been included, if it is included, no longer contains files, save resources, avoid repeating the definition of errors

Include and include_once differences:

The former encounters the include file, the latter will determine whether it has been included, if it is included, no longer contains files, save resources, avoid repeating the definition of errors

Require and include differences:

The former error, terminating the program execution. The latter error, continue the program execution.

?

Bit operations:

1. The highest bit of binary is the sign bit: 0 for positive, 1 for negative

2. Positive source code, anti-code, complement all the same

3. Negative number of the anti-code = Its original code sign bit is unchanged, the other bits take the reverse

4. The complement of negative number = Its anti-code +1

5.0 of the counter code, the complement is 0

6.php has no unsigned number, and the number in PHP is signed

7. In the computer operation, all in a complementary way to calculate

?

Array:

To create an array:

1. $arr [0] = 10;

2. $arr = Array (1, "Hello", true,3.14);

for ($i =0; $i<>< p=""><>

echo $arr [$i];

}

3. $arr = Array ("logo" = "Beijing", "name" = "sp", 5=>520);

Value method: $arr [' logo '], $arr ["name"], $arr [5]

1.foreach ($arr as $val) {

Echo $val;

}

2.foreach ($arr as $key = + $val) {

echo $key. ' = '. $val. '
';

}

Note: If an array is created and no subscript is assigned to an element, PHP automatically uses the current largest subscript value (integer) plus one as the subscript (keyword) for that element.

If you assign a value to an equally subscript element, the original value is overwritten

When accessing array elements, be aware that arrays are out of bounds

PHP Arrays can grow dynamically

Output array Condition: Print_r ($arr); or var_dump ($arr);

Array Common functions:

1.count (): Count ($arr);--> statistic array length

2.is_array (): Is_array ($arr);--> determine if the variable is an array

3.print_r () and Var_dump (): Displaying array information

4.explode ("", $str);--> splits the string into an array

Example:

$STR = "Beijing Shanghai Guangzhou Shenzhen Hong Kong Macau";

$arr = Explode ("", $str);

5.sort ():--> array sorting

6.unset ():--> deletes a key-value pair from an array, and the array does not rebuild the index

7.round (): Round (3.14)-->3 round (1.1415926,2)-->3.14

Tips on how to turn off notice levels:

Mode 1. Change in php.ini file Error_reporting-->error_reporting = e_all & ~e_notice

Mode 2. Add the following code to the page: error_reporting (E_all^e_notice);

Array sorting:

1. Bubble sort

function Bubblesort ($arr) {

$temp = 0;

for ($i =0; $i<>< p=""><>

for ($j =0; $j<>< p=""><>

if ($arr [$j]> $arr [$j +1]) {

$temp = $arr [$j];

$arr [$j]= $arr [$j +1];

$arr [$j +1]= $temp;

}

}

}

Print_r ($arr);

}

?>

2. Select sort

function Selectsort ($arr) {

$temp = 0;

for ($i =0; $i<>< p=""><>

$minValue = $arr [$i];

$minIndex = $i;

for ($j = $i +1; $j<>< p=""><>

if ($minValue > $arr [$j]) {

$minValue = $arr [$j];

$minIndex = $j;

}

}

$temp = $arr [$i];

$arr [$i]= $arr [$minIndex];

$arr [$minIndex]= $temp;

}

Print_r ($arr);

}

?>

3. Insert Sort

Function Insertsort (& $arr) {

for ($i =1; $i<>< p=""><>

$insertValue = $arr [$i];

$insertIndex = $i-1;

while ($insertIndex >=0&& $insertValue < $arr [$insertIndex]) {

$arr [$insertIndex +1]= $arr [$insertIndex];

$insertIndex--;

}

$arr [$insertIndex +1]= $insertValue;

}

Print_r ($arr);

}

?>

4. Quick Sort

function QuickSort ($left, $right,& $arr) {

$l = $left;

$r = $right;

$pivot = $arr [($left + $right)/2];

$temp = 0;

while ($l < $r) {

while ($arr [$l]< $pivot) $l + +;

while ($arr [$r]> $pivot) $r-;

if ($l >= $r) break;

$temp = $arr [$l];

$arr [$l]= $arr [$r];

$arr [$r]= $temp;

if ($arr [$l]== $pivot)--$r;

if ($arr [$r]== $pivot) + + $l;

}

if ($l = = $r) {

$l + +;

$r--;

}

if ($left < $r) QuickSort ($left, $r, $arr);

if ($right > $l) quickSort ($l, $right, $arr);

}

?>

Find:

1. Sequential Lookup

Function Search (& $arr, $findValue) {

$flag =false;

for ($i =0; $i<>< p=""><>

if ($findValue = = $arr [$i]) {

echo "Query to $findvalue, subscript for $i.";

$flag =true;

Break

}

}

if (! $flag) {

echo "not queried";

}

}

2. Two points Search

Function BinarySearch (& $arr, $findValue, $leftIndex, $rightIndex) {

Sort ($arr);

if ($leftIndex > $rightIndex) {

Echo ' not queried ';

Return

}

$middleIndex =round (($leftIndex + $rightIndex)/2);

if ($findValue > $arr [$middleIndex]) {

BinarySearch ($arr, $findValue, $middleIndex +1, $rightIndex);

}else if ($findValue < $arr [$middleIndex]) {

BinarySearch ($arr, $findValue, $leftIndex, $middleIndex-1);

}else{

echo "Query to $findvalue, subscript for $middleindex.";

}

}

?

Multidimensional Arrays:

Definition: $arr = array (array (), array () ...);

  • Related Article

    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.