php substr 去掉前n位_PHP全栈学习笔记16
修改端口號
image.png
通過網絡命令netstat –aon 找到進程號
image.png
php學習
image.png
常量一般是大寫字母構成,常量只能定義一次
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__; ?>常量、變量的命名規則:
以字母、下劃線開頭,后接字母、數字、下劃線
以$打頭命名變量,變量要先賦值后使用
同一個變量,即可以存儲數字也可以存儲字符串,也就是可以存儲任意類型的數據
變量不用指定數據類型,但必須賦值后才能使用
求字符串的長度:int strlen ( string 字符名 )
查找第一次出現的子串位置:int strpos
查找最后一次出現的子串位置:int strrpos
求字符串右邊n個字符構成的子串
顯示去掉擴展名的文件名
$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函數用于將日期格式化為指定格式
構造數組:$names = array("a","b","c"); 訪問數組元素:$names[0]、 $names[1]、 $names[2].函數explode,用于將字符串分割成多個子串構成的數組
關聯數組
方法: “鍵”=>值
數據類型
Boolean型
integer型
浮點型
字符串型
偽類型
mixed、number、void、callback
image.png
image.png
image.png
image.png
image.png
image.png
檢入
image.png
自定義函數模板
image.png
image.png
開發環境:wamp3.06 + Zend studio 12
調試配置
打開php配置文件php.ini
image.png
去掉xdebug前的所有注釋符號‘;’,也就是說使用wamp自帶的調試器
image.png
image.png
允許訪問服務器
image.png
修改httpd.conf,允許訪問服務器
image.png
image.png
image.png
zend Studio 中設置
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> <html> <body> <?php if (isset($_REQUEST['emailto'])) {$emailto = $_REQUEST['emailto']; $subject = $_REQUEST['subject'];$message = $_REQUEST['message'];if(mail($emailto,$subject,$message,"From:23232323@hzj.com")){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><form> 標簽的 enctype 屬性規定了在提交表單時要使用哪種內容類型。在表單需要二進制數據時,比如文件內容,請使用 “multipart/form-data”。
<input> 標簽的 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"]; } ?>保存被上傳的文件
<?phpif ((($_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 生命周期
開始 session_start() 函數必須位于 <html> 標簽之前
存儲 Session 變量
使用 PHP $_SESSION 變量
isset(變量): 判定一個變量是否已經設置。
unset() : 函數用于釋放指定的 session 變量
session_destroy() 函數徹底終結 session
PHP mail() 函數
PHP mail() 函數用于從腳本中發送電子郵件
最簡單的方式是發送一封文本 email
<?php$to = "someone@example.com"; $subject = "Test mail"; $message = "Hello! This is a simple email message.";$from = "someonelse@example.com"; $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( "someone@example.com", "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 異常處理
主動拋出異常:
throw 異常對象;
捕獲異常
try { 這是放可能產生異常的語句。} catch(Exception $e){異常的處理語句; } <?php foreach($_COOKIE as $key=>$value){setCookie($key,"",time()-60); } echo "刪除所有cookie!";php高級教程完結!
結言
好了,歡迎在留言區留言,與大家分享你的經驗和心得。
感謝你學習今天的內容,如果你覺得這篇文章對你有幫助的話,也歡迎把它分享給更多的朋友,感謝。
感謝!承蒙關照!您真誠的贊賞是我前進的最大動力!
總結
以上是生活随笔為你收集整理的php substr 去掉前n位_PHP全栈学习笔记16的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 内存VS CPU:速度、稳定性、兼容性全
- 下一篇: 达内php吾爱_2018年达内c++全套