PHP
跳至導覽
跳至搜尋
![]() | |
编程范型: | 物件導向、函數式 |
---|---|
設計者: | Rasmus Lerdorf |
實作者: | The PHP Development Team, Zend Technologies |
最近釋出日期: | 8.1.1 / 2021年12月17日 |
型態系統: | 動態、弱型別 |
啟發語言: | Perl、C |
作業系統: | 跨平台 |
授權方式: | PHP License |
網站: | PHP 官方網站 |
PHP(PHP: Hypertext Preprocessor)
技術文件
- PHP: PHP Manual - Manual
- 參照:『維基百科~PHP_syntax_and_semantics』
- 參照:『維基教科書~Category:Shelf:PHP_scripting_language』
開發工具
- IDE
- Eclipse PHP Development Tools = Eclipse + 【PHP Development Tools 】
- Zend Studio
- PHPEdit
- PhpED
- Komodo
- PHP Designer
- phpanywhere(免費PHP線上編輯器)
- 其他開發工具
- PHPRunner(21天試用版)
- PHP快取
參照:『維基百科~List_of_PHP_accelerators』
- 編譯器
- PHP程式碼加密工具
- Zend Guard……要花$
- 破解Zend加密的反轉工具 deZender - Google 搜尋
- 其它
- PhpDocumentor……PHP文件產生器,自動自PHP檔中抽出相關的注解產生相關的文件
相關設定
關於PHP.INI
- 除錯訊息
error_reporting = E_ALL display_errors = On
- 魔術引號
magic_quotes_gpc = Off magic_quotes_runtime = Off magic_quotes_sybase = Off
- register_globals
register_globals = Off
- 預設時區(台灣為GMT+8)
date.timezone = Asia/Taipei
- 允許上傳大檔案
memory_limit = 99M max_execution_time = 300 upload_max_filesize = 20M post_max_size = 24M
關於.htaccess
關於PHP的Debug
教學文件
PHP與WebService
- Webservice Helper...讓 PHP 可產生 WSDL
- Mindreef and XMethods...讓 WSDL 有一個類似 Web Service 的友善介面
- Yahoo員工對上述兩個工具的簡介
PHP與Flash
UTF8
相關套件
Class或函數
Framework
參照:『維基百科~Category:PHP_frameworks』
Blog
Wiki
討論區
內容管理系統
MySQL資料庫管理
- phpMyAdmin,參照:『維基百科~PhpMyAdmin』。
- phpMyBackupPro (pMBP)……MySQL的備份機制
電子商務(網路商店)
Bug追蹤系統
專案管理
圖庫系統
FAQ
客服系統
- Crafty Syntax Live Help
- Help Center Live
- osTicket
- PerlDesk
- PHP Support Tickets
- Support Logic Helpdesk
- Support Services Manager
Billing
Mailing Lists
網站流量與統計表
聊天室
File explorer
傳訊
JavaScript壓縮工具
圖表
- PHP/SWF Charts
- Chart Manual
- JpGraph - Most powerful PHP-driven charts
- PHP Charts & Graphs | Five Minutes to Your First Chart!
- pChart 2.0 - a PHP charting library
- pChart - a PHP Charting library
報表
討論區
- 程式設計俱樂部 PHP討論區
- 台灣PHP聯盟 新手 - 進階
- 藍色小舖 BlueShop PHP討論區
- 喜悅國際村 基礎 - 進階 - Code分享
- EcStart PHP 技術討論論壇 PHP 討論區
FAQ
PHP輸出網頁亂碼
驗證email是否有效
格式化日期
以2010年3月4日為例 Y年m月d日 → 2010年03月04日 Y年n月j日 → 2010年3月4日
PHP安全模式
- Safe Mode(有些PHP下的函數可能導致罷工)
PHP 5.3.0+ 未設定系統預設時區
- 可能導致網頁上出現下列警告訊息
- Warning: strtotime() [function.strtotime]: It is not safe to rely on the system's timezone settings.
- Warning: date() [function.date]: It is not safe to rely on the system's timezone settings.
date_default_timezone_set('Asia/Taipei');
PHP檔案減肥
- 去除PHP程式碼之間的註解跟縮排
php -w test.php > test.striped.php
如何建立更安全的登入網頁
停用不安全的函數
- 在php.ini
disable_functions = show_source, system, shell_exec, passthru, exec, popen, proc_open
php.net官方網站是OpenSource
升級到PHP 7.0的注意事項
- Migrating from PHP 5.6.x to PHP 7.0.x
- Backward incompatible changes
- PHP核心開發者告訴你PHP 7的五大效能密技 - iThome
關於檔案下載
PHP如何Debug
- 顯示PHP錯誤訊息 加速偵錯(Debug)效率
- 使用 VS Code + XAMPP 進行 PHP 的開發與Debug
- PHP Storm(30天試用,付費軟體,能夠Debug的IDE工具)
- 或是把PHP執行時的一些資訊輸出到Google Chrome的開發工具
剝離HTML與PHP標籤
自動載入
function autoload($className) { $className = ltrim($className, '\\'); $fileName = ''; $namespace = ''; if ($lastNsPos = strrpos($className, '\\')) { $namespace = substr($className, 0, $lastNsPos); $className = substr($className, $lastNsPos + 1); $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; } $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; require $fileName; } spl_autoload_register('autoload');
常見的PHP錯誤訊息
A non-numeric value encountered
- 錯誤
$a = '123a'; $b = 'b456'; echo $a+$b; //A non-numeric value encountered
- 解法(轉成數值)
echo intval($a)+intval($b);
Deprecated: Array and string offset access syntax with curly braces is deprecated
- 錯誤
$str = "test"; echo($str{0});
- 解法(把{}改為[])
echo($str[0]);
Deprecated: Non-static method
- 錯誤
class MyClass { function Test1() { } } function Test2() { MyClass::Test1(); //Deprecated: Non-static method }
- 解法(改函數的宣告)
class MyClass { public static function Test1() { } }
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP
- 錯誤 (class的建構函數名稱必須為 __construct )
class MyClass { //Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP function MyClass() { } }
- 解法(把建構函數的名字改為 __construct )
function __construct() {
Deprecated: Function create_function() is deprecated
- 錯誤(create_function()已停用)
$callback_2 = create_function('$matches', 'return "[" . str_replace("|", "", $matches[1]) . "]";');
- 解法(改用Anonymous functions的寫法)
$callback_2 = function($matches) {return "[" .str_replace("|", "", $matches[1]). "]";};
implode(): Passing glue string after array is deprecated
- 錯誤
$words = static::words($nbWords); $words[0] = ucwords($words[0]); $ret = implode($words, ' ') . '.'; //implode(): Passing glue string after array is deprecated
- 解法(傳入參數的順序顛倒)
$ret = implode(' ', $words) . '.';
syntax error, unexpected 'new' (T_NEW)
- 錯誤
class MyClass { } function Test1() { $SomeClass1 = "MyClass"; $obj =& new $SomeClass1; //unexpected 'new' (T_NEW) }
- 解法
$obj = new $SomeClass1();
Fatal error: Call to undefined function mcrypt_encrypt()
- mcrypt_encrypt在PHP 7.2版以後被移除
- 解法
Warning: file-get-contents() failed to open stream: HTTP request failed!
- PHP: file_get_contents - Manual
- api - PHP file_get_contents() returns "failed to open stream: HTTP request failed!" - Stack Overflow
- 解法
- 改用curl
- 或是加上 ini_set("allow_url_fopen", 1);
- 或是檢查OS的防火牆設定(例如 SELinux )