三、建立一個文件,在第一行寫上下面代碼php
#! /usr/local/php/bin/php <?php ....
str_replace('\\', '/', __FILE__)
echo PHP_EOL; //windows平臺至關於 echo "\r\n"; //unix\linux平臺至關於 echo "\n"; //mac平臺至關於 echo "\r";
public function __construct() { //控制器初始化 if(method_exists($this,'_initialize')) $this->_initialize(); }
<?php $var1 = 1; function test(){ global $var1; unset($var1); } test(); echo $var1; //輸出1 ?> <?php $var1 = 1; function test(){ unset($GLOBALS[‘var1′]); } test(); echo $var1;//輸出空白 ?>
@include('file'); //等同 $foo = error_reporting(0); include('file'); error_reporting($foo); //因此不少步驟都重複了,因此儘可能少用,避免開銷
<?php $url = 'http://www.51-n.com/'; class test{ public $url; function __construct($url=''){ $this->url = $url; } function showUrl(){ echo $this->url; } } $test = new test($url); $test->showUrl(); ?>
<?php $url = 'http://www.51-n.com/'; class test{ public $url; function showUrl(){ global $url; $this->url = $url; echo $this->url; } } $test = new test($url); $test->showUrl(); ?>
<?php $url = 'http://www.51-n.com/'; class test{ public $url; function showUrl(){ $this->url = isset($GLOBALS['url'])?$GLOBALS['url']:''; echo $this->url; } } $test = new test($url); $test->showUrl(); ?>
& & " " ' ' (for ENT_HTML401) or ' (for ENT_XML1, ENT_XHTML or ENT_HTML5), but only when ENT_QUOTES is set < < > >
$str='<a href="test.html">測試頁面</a>'; echo htmlentities($str); // <a href="test.html">²âÊÔÒ³Ãæ</a> $str='<a href="test.html">測試頁面</a>'; echo htmlspecialchars($str); // <a href="test.html">測試頁面</a>
$HTTP_RAW_POST_DATA
與php://input
做用同樣,但區別以下:一、$HTTP_RAW_POST_DATA
須要配置 php.ini 中的 always_populate_raw_post_data
值爲 On 纔會生效,而 php://input
無需配置就生效
二、當 $_POST
與 php://input
能夠取到值時 $HTTP_RAW_POST_DATA
爲空
三、$HTTP_RAW_POST_DATA
從php5.6起就開始過期了,並在php7.0中正式刪除,而用 php://input
替代html
相同點:
一、不能用於 enctype="multipart/form-data"
(也叫Content-Type)linux
$_POST
與 php://input
的區別以下:一、Content-type
爲application/x-www.form-urlencoded
或multipart/form-data
時,$_POST
纔有值,獲得的數據是通過urldecode
解碼處理
二、除了Content-type
爲multipart/form-data
時,php://input
沒值之外,其餘狀況都有值,例如:application/json、text/xml、text/plain
三、文件上傳只能經過$_POST
獲取值
四、其餘方式如:put/delete,也只能經過php://input
獲取json
true
,不然返回false語句
不是函數,沒有返回值,可輸出多個變量值,不能輸出數組和對象
,只能打印簡單類型(如int,string,bool,float,null)。語句
不是函數,有返回值 1 ,只能輸出一個變量,不能輸出數組和對象
,只能打印簡單類型(如int,string,bool,float,null)。echo沒有返回值,print有返回值
echo能夠輸出多個參數,print只能夠輸出一個參數
數組打印
int數據類型
int數據類型
//位與或位或時 數據類型轉換 TRUE => 1 FALSE => 0 ''與'0' => 0 //按字符串轉數值類型的規矩 [] => 0 非空數組 => 1 12 | [] //12 TRUE & '8' //0 TRUE | '8' //9
bool數據類型
bool數據類型
php數據原型
輸出$msg = 'xxx'; var_export($msg); //輸出'xxx' var_export($msg,true); //不輸出,只返回 'xxx'
$msg = 'nihao'; $content = '<?php'.PHP_EOL; $content.= '$a ='.var_export($msg,true).';'.PHP_EOL; $content.= 'echo $a;'.PHP_EOL; $content.= '?>'; file_put_contents('./test.php',$content);
包含進來的文件,其實與原文件至關合並
一、外面文件能夠訪問裏面文件定義的變量(在include以後定義的變量) 二、裏面文件能夠訪問外面文件在include以前定義的變量