Development environment wamp3.06 + Zend studio 12 debug configuration

image.png

<?php
$fileName = "php大师.test.php";
//补充程序,显示文件名(不包括扩展名)
$start = strrpos($fileName, "."); $newStr = substr($fileName,0, $start); var_dump ( $newStr ); ?>
<?php
for($i=100;$i<1000;$i++){ if(($i*$i)%1000==$i) { echo $i; echo "<br/>"; } } ?> 
<?php
$x = "hello";
switch ($x) {
    case 1 : echo "Number 1"; break; case 2 : echo "Number 2"; break; case "hello" : echo "hello"; break; default : echo "No number between 1 and 3"; } ?> 
<?php
$students = array(array("name"=>"张三","age"=>25,"height"=>180),array("name"=>"李四","age"=>22,"height"=>170)); echo $students[0]["name"]; echo "<br/>"; echo $students[1]["name"]; ?> 
<?php
// 显示右边n个字符
$n = 5;
$oldStr = "dsfasfasf"; $rightStr = subStr ( $oldStr, strlen($oldStr) - $n ); var_dump ( $rightStr ); ?>
<html> <body>
<form action="welcome.php" method="post">  Name: <input type="text" name="name" />  Age: <input type="text" name="age" />  <input type="submit" /> </form> </body> </html> 
好好学习,天天向上
<br/>
<?php
echo "hello world"; define("ABC",1000); var_dump(defined("ABC")); echo "<br/>"; echo constant("ABC"); echo PHP_OS; echo "<br/>"; echo PHP_VERSION; echo "<br/>"; echo __FILE__; define('NAME','php'); define('NAME','linux'); echo NAME; ?> <img src="/test/a.jpg"></img>

Modify the port number

image.png

netstat -aon find the process ID through the network command

image.png

learn php

image.png

Constants are generally composed of capital letters, constants can only be defined once

bool define ( string name, mixed value [, bool case_insensitive] )
bool defined ( string name )

<?php
echo "中文测试<br/>";
print "hello world!"; echo "<br/>"; echo "<img src='/test/a.jpg'></img>"; define("PI",3.14); var_dump(defined("Pi")); echo PHP_OS; echo "<br/>"; echo PHP_VERSION; echo "<br/>"; echo __FILE__; ?>

Naming constants, variables:
the letters, begins with an underscore, followed by letters, numbers, underscores

Beginning at $ named variables, variable assignment after first use of
the same variable, which can store digital can also store the string, that is, you can store any type of data
in order to use the variables do not specify a data type, but must be assigned

Seeking string length: int strlen (string character name)
substring position to find the first occurrence of: int strpos
Find position of last occurrence of a substring of: int strrpos

Find the right character string composed of n substring
substr (original string, - $ n) or: substr (original string, strlen (original string) - $ n)

Strips the filename extension

$dotpos = strpos($fileName,".");
echo substr($fileName,0, $dotpos);
$y = $x++ 相当于{$y=$x; $x=$x+1;} $y = $x-- 相当于{$y=$x; $x=$x-1;} $y = ++$x 相当于{$x=$x+1; $y=$x;} $y = $x-- 相当于{$x=$x-1; $y=$x;}
对于表达式:A && B,如果A为假,则不再计算表示式B的值
对于表达式:A || B,如果A为真,则不再计算表示式B的值

date function sets the date format for the specified format

构造数组:$names = array("a","b","c"); 
访问数组元素:$names[0]、 $names[1]、 $names[2].

Function explode, is divided into an array of strings for a plurality of substrings constituting

Associative array
Method: "button" => Value

Data type
Boolean type
integer type
float
string

Pseudo type
mixed, number, void, callback

<?php
// 求1!+2!....+10!

// 声明一个控制变量,初始化
$i = 1; // 声明一个存储和的变量 $sum = 0; // 声明一个变量存储n!,初始化化为1; $rank = 1; // 计算$i的阶乘,计算完马上累加科 while ( $i <= 10 ) { // 计算$i!= ($i-1)!*$i $rank *= $i; // 累加 $sum += $rank; // 改变循环变量值 $i ++; } echo $sum . "<br/>"; // 求1!+2!....+10! $x = 1; $sum2 = 0; while ( $x <= 10 ) { // 计算$x! $rank2 = 1; $y = 1; while ( $y <= $x ) { $rank2 *= $y; $y ++; } // 累加 $sum2 += $rank2; // 改变循环变量值 $x ++; } echo $sum2 . "<br/>"; // 求1.....100之间素数 // 8 = 2*4 7是素数,因为7/2 7/3 7/4....7/6,7不能被整除 for($i = 2; $i <= 100; $i ++) { // 假设是素数 $isPrime = true; //除数不用到$i-1,到sqrt($i) for($j = 2; $j <= sqrt($i); $j ++) { if ($i % $j == 0) { $isPrime = false; break; } } //验证假设有没有被修改 if ($isPrime == true) { echo $i . " "; } } $arr=array("one", "two", "three"); //依次取出数组每一个元素放到$aa foreach ($arr as $aa){ echo $aa. " "; } echo "<br/>"; // 求1!+2!....+10! function Rank($n){ $rank = 1; for($i=1;$i<=$n;$i++){ $rank *= $i; } return $rank; } $sum = 0; for($i=1;$i<=10;$i++){ $sum += Rank($i); } echo $sum; ?>

image.png

image.png

image.png

image.png

image.png

image.png

Check In

image.png

Custom function template

image.png

image.png

Development Environment: wamp3.06 + Zend studio 12
debug configuration

Open the php configuration file php.ini

image.png

Note remove all symbols before xdebug ';', that is to say the use of built-in debugger wamp

image.png

image.png

Allow access to the server

image.png

Modify httpd.conf, allowing access to the server

image.png

image.png

image.png

zend Studio Set

image.png

image.png

image.png

image.png

Servers
配置local Apache HTTP Server

image.png

image.png

image.png

配置exe文件
image.png

image.png

配置debug

image.png

修改Document Root为

image.png

image.png

image.png

配置默认字符集

image.png

配置默认字体大小

image.png

image.png

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <?php // if((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == // "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && // ($_FILES["file"]["size"] < 20000)) { // if ($_FILES["file"]["error"] > 0) { // echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; // } // else { if (file_exists ( "upload/" . $_FILES ["file"] ["name"] )) { echo $_FILES ["file"] ["name"] . " already exists. "; } else { $newname = iconv ( "utf-8", "gb2312", $_FILES ["file"] ["name"] ); move_uploaded_file ( $_FILES ["file"] ["tmp_name"], "upload/" . $newname ); // move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" // .$_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES ["file"] ["name"]; } // } // } else { echo "Invalid file"; } ?> </body> </html>
<html>
<body>
<?php $week = array("星期日","星期一","星期二","星期三","星期四","星期五","星期六"); $day = date("w"); $mydate = date("你好! 现在是Y年n月j日H点i分,$week[$day]"); echo $mydate; ?> </body> </html>
<?php  
    session_start(); 
    if(isset($_SESSION['user'])){ header("Location:main.php");//自动跳转到main.php }else{ //获取用户输入 $username = $_POST [ 'username' ]; $passcode = $_POST [ 'passcode' ]; $cookie = $_POST [ 'cookie' ]; //判断用户是否存在,密码是否正确 if ($username =="hhh" && $passcode == "12345") { $_SESSION['user']=$username; header("Location:main.php" );//自动跳转到main.php } else{ echo "用户名或密码错误"; } } ?>
<?php header('Content-type:text/html;charset=utf-8'); ?>
<html> <head> <meta http-equiv= "Content-Type" content=" text/html; charset=UTF-8"> </head> <body> <?php if (isset ( $_COOKIE ["username"] )) { header ( "location: main1.php" ); } else { $username = $_POST ['username']; $passcode = $_POST ['passcode']; $cookie = $_POST ['cookie']; if ($username == "hhh" && $passcode == "12345") { switch ($cookie) { case 0 : setcookie ( "username", $username ); break; case 1 : setcookie ( "username", $username, time () + 24 * 60 * 60 ); break; case 2 : setcookie ( "username", $username, time () + 30 * 24 * 60 * 60 ); break; case 3 : setcookie ( "username", $username, time () + 365 * 24 * 60 * 60 ); break; } header ( "location: main.php" ); } else { echo ""; } } ?> </body> </html>

发送邮箱

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <html> <body> <?php if (isset($_REQUEST['emailto'])) { $emailto = $_REQUEST['emailto']; $subject = $_REQUEST['subject']; $message = $_REQUEST['message']; if(mail($emailto,$subject,$message,"From:[email protected]")){ echo "谢谢使用本程序!"; }else{ echo "未能发送成功!"; } }else{ echo "<form method='post' action='sendemail.php'>EmailTo:<input name='emailto' type='text' /><br />Subject: <input name='subject' type='text' /><br />Message:<br /><textarea name='message' rows='15' cols='40'></textarea><br /><input type='submit' /></form>"; } ?> </body> </html>

PHP Date() 函数可把时间戳格式化为可读性更好的日期和时间

语法

date(format,timestamp)
d - 月中的天 (01-31) 
m - 当前月,以数字计 (01-12) Y - 当前的年(四位数) 
<?php 
  echo date("Y/m/d"); 
  echo "<br />"; echo date("Y.m.d"); echo "<br />"; echo date("Y-m-d"); ?>

PHP 引用文件
include() 或 require()
它们处理错误的方式不同
include() 函数会生成一个警告
require() 函数会生成一个致命错误

PHP 文件处理

fopen ( string $filename , string $mode )

关闭文件

fclose() 函数用于关闭打开的文件

逐行读取文件

fgets() 函数用于从文件中逐行读取文件

PHP 文件上传

<html> <body> 
  <form action="upload_file.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> </body> </html> 

标签的 enctype 属性规定了在提交表单时要使用哪种内容类型。在表单需要二进制数据时,比如文件内容,请使用 “multipart/form-data”。

 标签的 type=“file” 属性规定了应该把输入作为文件来处理。

PHP 的全局数组 $_FILES,存放了上传到服务器的文件的所有信息

$_FILES["file"]["name"] - 被上传文件的名称 
$_FILES["file"]["type"] - 被上传文件的类型 
$_FILES["file"]["size"] - 被上传文件的大小 $_FILES["file"]["tmp_name"] - 存储在服务器的文件的临时副本的名称 $_FILES["file"]["error"] - 由文件上传导致的错误代码

“upload_file.php”文件

<?php if ($_FILES["file"]["error"] > 0) {  echo "Error: " . $_FILES["file"]["error"] . "<br />"; } else {  echo "Upload: " . $_FILES["file"]["name"] . "<br />";  echo "Type: " . $_FILES["file"]["type"] . "<br />";  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";  echo "Stored in: " . $_FILES["file"]["tmp_name"]; } ?> 

保存被上传的文件

<?php
 if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> 

编码方案

<?php header(‘Content-type: text/html; charset=gbk’);?>//放在php文档的头部
<meta http-equiv= "Content-Type" content=" text/html; charset=UTF-8"> 

编码的转换

string iconv ( string $in_charset , string $out_charset , string $str )

什么是 Cookie?
Cookies-在客户端保存信息

cookie 常用于识别用户。cookie 是服务器留在用户计算机中的小文件。每当相同的计算机通过浏览器请求页面时,它同时会发送 cookie。通过 PHP,您能够创建并取回 cookie 的值。

如何创建 cookie?
setcookie() 函数用于设置 cookie。

语法

setcookie(name, value, expire, path, domain); 

如何删除 cookie?

<?php       // set the expiration date to one hour ago setcookie("user", "", time()-3600);
 ?> 

Session-在服务器端保存用户信息

PHP session 变量用于存储有关用户会话的信息,或更改用户会话的设置。

Session 的工作机制是:为每个访问者创建一个唯一的 id (UID),并基于这个 UID 来存储变量。UID 存储在 cookie 中,亦或通过 URL 进行传导。

Session 生命周期

Before the start tag session_start () function must be located

Session variables stored
using PHP $ _SESSION variable

<?php session_start(); $_SESSION['views']=1; ?> <?php echo "Pageviews=". $_SESSION['views']; ?>

isset (variable): determine whether a variable has been set.
unset (): function used to free a session variable
session_destroy () function is a complete end session

PHP mail () function
PHP mail () function is used to send e-mail from a script

The easiest way is to send a text email

<?php
  $to = "[email protected]"; 
  $subject = "Test mail";   $message = "Hello! This is a simple email message.";    $from = "[email protected]";   $headers = "From: $from";   mail($to,$subject,$message,$headers);    echo "Mail Sent."; ?> 

mailform.php

<?php 
if (isset($_REQUEST['email'])) {    $email = $_REQUEST['email'] ;   $subject = $_REQUEST['subject'] ;   $message = $_REQUEST['message'] ;   mail( "[email protected]", "Subject: $subject", $message, "From: $email" );   echo "Thank you for using our mail form"; } else {   echo "<form method='post' action='mailform.php'>   Email: <input name='email' type='text' /><br />   Subject: <input name='subject' type='text' /><br />   Message:<br /> <textarea name='message' rows='15' cols='40'> </textarea><br />   <input type='submit' /> </form>"; } ?>

PHP exception handling

Initiative to throw an exception:
the throw exception objects;

Catch the exception

 try { 
  这是放可能产生异常的语句。
 }  catch(Exception $e)
 {
     异常的处理语句;   
}
<?php
foreach($_COOKIE as $key=>$value){
    setCookie($key,"",time()-60); } echo "删除所有cookie!";

Guess you like

Origin www.cnblogs.com/daofaziran/p/11571921.html