search

php搭建及基础

1.php开发环境的搭建:

1.在linux下搭建

linux+apache+mysql+php

2.在window下搭建

apache+php+mysql+phpmyadmin

查看端口:cmd-->netstat -an

安装方式:

1.套件安装:

常用套件:appserv,wmap,phpStudy

Apache HTTP Server:apache web服务器

MySQL Database:MySQL数据库

PHP Hypertext Preprocessor:PHP核心

phpMyAdmin:管理MySQL数据库的图形化工具-->next

?

Server Name:localhost

Administrator's Email Address:53032104@qq.com-->管理员邮箱

Apache HTTP Port:8000-->端口号-->next

?

Please enter Root password for MySQL Server-->root用户密码

Enter root password:root

Re-enter root password:root

MySQL Server Setting

Characher Sets and Collations:UTF-8 Unicode-->指定数据库编码,建议UTF-8

?

2.自定义安装:

1.apache

测试:http://localhost

2.php核心包:(php官网:http://www.php.net)解压即可

windows下使用Apache+PHP,选择VC6版本

windows下使用IIS+PHP,选择VS9版本

?

apache和php整合:

1.在D:\phpStudy\Apache2\conf\httpd.conf文件中130行左右加入:

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或者.phtml,将由php来处理

?

2.在php安装目录下:把php.ini-development文件重命名为php.ini

3.在php.ini中搜索extension_dir = "./",打开这一行,指定php安装目录下的ext文件路径

extension-dir = "D:/phpStudy/PHP5/ext"

?

测试:

在apache安装目录下的htdocs目录中新建test.php文件,代码如下

phpinfo();

?>

重新启动apache:http://localhost/test.php

?

3.MySQL数据库:(MySQL官网:http://www.mysql.com)

测试:

1.写一段php代码来测试是否成功

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

if($conn){

echo "连接mysql数据库 ok!";

}else{

echo "连接mysql数据库 不ok!";

}

?>

2.安装一个phpmyadmin来测试是否可用(管理mysql)

安装方式:解压到htdocs文件夹下即可,进入该目录下的index.php文件

进入方式:http://localhost:8000/phpMyAdmin/index.php

?

2.http://www.comsenz.com

1.下载discus论坛代码

2.解压到htdocs文件夹下

3.修改文件config.inc.php:

$dbhost = 'localhost';// 数据库服务器

$dbuser = 'root';// 数据库用户名

$dbpw = 'root';// 数据库密码

$dbname = 'discuz';// 数据库名

$pconnect = 0;// 数据库持久连接 0=关闭, 1=打开

?

$database = 'mysql';// 论坛数据库类型,请勿修改

$dbcharset = 'utf8';// MySQL 字符集, 可选 'gbk', 'big5', 'utf8', 'latin1', 留空为按照论坛字符集设定

?

$charset = 'utf-8';// 论坛页面默认字符集, 可选 'gbk', 'big5', 'utf-8'

$headercharset = 0;// 强制论坛页面使用默认字符集,可避免部分服务器空间页面出现乱码,一般无需开启。 0=关闭 1=开启

?

$forumfounders = 'admin';// 论坛创始人 UID, 可以支持多个创始人,之间使用 “,” 分隔。

注:需要设置php.ini中:short_open_tag = on

4.访问discus下的install.php文件,进行数据库安装

安装完成后:

UCenter的访问网址:http://localhost/upload/ucenter

UCenter 创始人密码:admin

DISCUZ!的访问网址:http://localhost/upload/bbs

管理员访问网址:http://localhost/upload/bbs/admincp.php

管理员帐号:admin 管理员密码:admin

UCenter Home的访问网址:http://localhost/upload/home

管理员访问网址:http://localhost/upload/home/admincp.php

管理员帐号:admin 管理员密码:admin

?

?

在一台apache服务器中配置网站:

1.如需在apache服务器中创建web站点,需要启用httpd-vhosts.conf文件添加:

note:确保dns client服务是启动状态

2.配置的主机要想被外部访问,必须在DNS服务器或windows系统中注册

?

思路:

1.通过端口来区分不同的虚拟主机

一:按照绑定一个站点的方法做好准备

1.开发网站 D:/myblog

2.配置我们的httpd.conf文件?

启用httpd-vhosts.conf

注释DocumentRoot "D:/apache/htdocs"

3.找到文件conf/extra/http-vhosts.conf文件

模板:

DocumentRoot "D:/myblog"

DirectoryIndex index.php index.html

Options FollowSymLinks

AllowOverride None

Order allow,deny

Allow from all

4.在hosts文件中添加ip和域名之间的对象关系

路径:C:\Windows\System32\drivers\etc\hosts

添加:127.0.0.1www.moluo.com

5.测试:访问http://www.moluo.com:80

?

二.添加一个新的域名于该ip绑定

1.开发一个新的网站

2.配置httpd-vhosts.conf,添加新的虚拟主机

DocumentRoot "D:/myblog2"

DirectoryIndex index.php index.html

Options FollowSymLinks

AllowOverride None

Order allow,deny

Allow from all

3.在httpd.conf文件中让apache监听82端口

Listen 82

4.在hosts文件中添加ip和域名之间的对象关系

路径:C:\Windows\System32\drivers\etc\hosts

添加:127.0.0.1www.fengpeng.com

5.测试:访问http://www.fengpeng.com:82

?

2.通过ServerName区分不同的虚拟主机

1.开发网站 D:/myblog

2.在httpd-vhosts.conf文件中添加配置

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..在hosts文件中添加ip和域名之间的对象关系

路径:C:\Windows\System32\drivers\etc\hosts

添加:127.0.0.1www.moluo.com

4.测试:访问http://www.moluo.com

访问http://www.fengpeng.com

?

web站点的含义:多个web资源的集合,包括php/html/js/css

php的基本语法介绍:

如果只是为了显示一个变量:=变量?>

php代码注释:

//单行注释 ?

/*多行注释*/

引号区别:

单引号:将数据原封不动的输出

双引号:解析数据特殊字符,变量等!

常量定义:

注:1.命名:大写,下划线

2.不需要$开头

3.一旦赋值,不可改变

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

2.const TAX_RATE = 0.02;

金字塔实例:

$n=10;

for($x=1;$x

for($z=1;$z

echo " ";

}

for($y=1;$y

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

echo '*';

}else{

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

echo '*';

}else{

echo " ";

}

}

}

echo '
';

}

?>

?

函数介绍:(常用:require_once())

基本格式:

function method($a,$b){

echo $a+$b;

}

?>

?

a.php 页面调用 b.php 定义的函数,可以使用如下指令

require ?require_once ?include ?incliude_once

举例:

1.require 'b.php';

2.require ('b.php');

3.$filename='b.php';

?require $filename;

?>

require 和 require_once 区别:

前者遇到即包含文件,后者会判断是否已经包含,如果包含过了,则不再包含文件,省资源,避免重复定义的错误

include 和 include_once 区别:

前者遇到即包含文件,后者会判断是否已经包含,如果包含过了,则不再包含文件,省资源,避免重复定义的错误

require 和 include 区别:

前者出错,终止程序执行.后者出错,继续程序执行.

?

位运算:

1.二进制的最高位是符号位:0表示正数,1表示负数

2.正数的源码,反码,补码都一样

3.负数的反码=它的原码符号位不变,其它位取反

4.负数的补码=它的反码+1

5.0的反码,补码都是0

6.php没有无符号数,php中的数都是有符号的

7.在计算机运算的时候,都是以补码的方式来运算的

?

数组:

创建数组:

1.$arr[0] = 10;

2.$arr = array(1,"hello",true,3.14);

for($i=0;$i

echo $arr[$i];

}

3.$arr = array("logo"=>"北京","name"=>"sp",5=>520);

取值方式:$arr['logo'],$arr["name"],$arr[5]

1.foreach($arr as $val){

echo $val;

}

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

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

}

注意:如果创建一个数组,没有给某个元素指定下标,php就会自动的用目前最大的那个下标值(整数)加一作为该元素的下标(关键字)

如果给某个同样下标元素赋值,则会覆盖原来的值

访问数组元素时,注意数组越界

php数组可以动态增长

输出数组情况:print_r($arr);或者var_dump($arr);

数组常用函数:

1.count():count($arr);-->统计数组长度

2.is_array():is_array($arr);-->判断变量是否为数组

3.print_r()和var_dump():显示数组信息

4.explode(" ",$str);-->拆分字符串成为数组

示例:

$str = "北京 上海 广州 深圳 香港 澳门";

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

5.sort():-->数组排序

6.unset():-->删除数组的某个键值对,数组不会重建索引

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

如何关闭notice级别的提示:

方式1.在php.ini文件中改动error_reporting-->error_reporting = E_ALL & ~E_NOTICE

方式2.在页面中加入如下代码:error_reporting(E_ALL^E_NOTICE);

数组排序:

1.冒泡排序

function bubbleSort($arr){

$temp=0;

for($i=0;$i

for($j=0;$j

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

$temp=$arr[$j];

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

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

}

}

}

print_r($arr);

}

?>

2.选择排序

function selectSort($arr){

$temp=0;

for($i=0;$i

$minValue = $arr[$i];

$minIndex = $i;

for($j=$i+1;$j

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

$minValue=$arr[$j];

$minIndex=$j;

}

}

$temp=$arr[$i];

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

$arr[$minIndex]=$temp;

}

print_r($arr);

}

?>

3.插入排序

function insertSort(&$arr){

for($i=1;$i

$insertValue=$arr[$i];

$insertIndex=$i-1;

while($insertIndex>=0&&$insertValue

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

$insertIndex--;

}

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

}

print_r($arr);

}

?>

4.快速排序

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

$l=$left;

$r=$right;

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

$temp=0;

while($l

while($arr[$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

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

}

?>

查找:

1.顺序查找

function search(&$arr,$findValue){

$flag=false;

for($i=0;$i

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

echo "查询到$findValue,下标为$i.";

$flag=true;

break;

}

}

if(!$flag){

echo "未查询到";

}

}

2.二分查找

function binarySearch(&$arr,$findValue,$leftIndex,$rightIndex){

sort($arr);

if($leftIndex>$rightIndex){

echo '未查询到';

return;

}

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

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

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

}else if($findValue

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

}else{

echo "查询到$findValue,下标为$middleIndex.";

}

}

?

多维数组:

定义:$arr = array(array(),array()...);

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software