PHP
PHP 是一本正在翻譯的教科書
|
什麼是PHP?
[編輯]PHP 目前被廣泛的應用,它也是開源軟件運動中一個成功的例子。PHP受歡迎是因為其語法類似C、它的速度以及它的簡單。 PHP是目前分為兩個主要版本: PHP 7和PHP 8。
相信大家也曾經嘗試過在網站入使用登入登出的功能。而這類登入的功用,大多數會利用伺服器語言來達成,而你也很可能與PHP打交道。 PHP語言由Rasmus Lerdorf發明。當初的他寫這個小程式,目的只是希望追蹤瀏覽者的資料。
基本上,PHP使靜態的網頁動態化。「PHP」是一個遞歸的縮寫,它表示「PHP: Hypertext Preprocessor(PHP:超文本預處理器)」。PHP 對超文本文檔進行預處理(即 PHP 在輸出被發送到瀏覽器之前進行處理)。因此,頁面可以根據條件,在被用戶看到之前做出改變。這可以被用來在頁面上寫一些東西,創建一個多行的表格,使它的行數正好等於用戶訪問的次數,或者,將網頁與 web 數據庫(例如 MySQL)相整合。
在開始伺服器處理的奇妙旅程之前,您最好對超文本標記語言作一些基本的了解。PHP 也被用來開發 GUI 應用程式;PHP-GTK 用來構建圖形用戶界面(Graphical User Interfaces,GUI)。
安裝及設置
[編輯]注意:在貢獻前,請閱讀討論頁。
Learning the Language
[編輯]The Basics
[編輯]- This section is about things that are important for any type of PHP development. Useful for a PHP programmer of any level.
- Beginning with "Hello World!" (10 Feb 2006)
- Nuts and Bolts (14 Jan 2006)
- Commenting and Style (14 Jan 2006)
- Arrays (10 Feb 2006)
- Control structures
- Functions (10 Feb 2006)
- Files (12 Feb 2008)
- Mailing (14 Jan 2006)
- Cookies (14 Jan 2006)
- Sessions (2008-05-07)
- Databases
- Integration Methods (HTML Forms, etc.) (14 Jan 2006)
Advanced PHP
[編輯]- Advanced PHP includes high level programming and PHP techniques designed to make PHP even more useful and powerful.
Object Oriented Programming (OOP)
[編輯]Templating
[編輯]- Why Templating
- Templates
- Caching
- SMARTY templating system
- PRADO Component Framework
- Flat Frog templating system (23 march 2006)
- XSL
Libraries
[編輯]Frameworks
[編輯]Security
[編輯]- Configuration: Register Globals
- SQL Injection Attacks
- Cross Site Scripting Attacks
- Building a secure user login system
See also the section on avoiding session fixation in the Sessions chapter.
Command-Line Interface (CLI)
[編輯]Code Snippets
[編輯]Useful for any beginners to learn code from.
PHP 4 & 5
[編輯]Basic Level
[編輯]echo "the text to print";
- This language construct will echo the text between the quotes. This is not a function but a language construct.echo "$var";
- Notice the double quotation marks. Because double quotation marks are used, this will print the value of the variable. If $var="Bobby", this will output:
Bobby
echo '$var';
- Notice that the quotation marks are now single. This will output the literal keystrokes inside the quotes. The example will output:
$var
$var="Jericho";echo "Joshua fit the battle of $var.";
- Other than substituting the value of a variable for the variable name (and one or two other minor items), double quotes will quote literal keystrokes. So this will output:
Joshua fit the battle of Jericho.
Again, if single quotes were used — 'Joshua fit the battle of $var';
— this would output:
Joshua fit the battle of $var.
echo $var;
- If you only want to print the value of a variable, you don't need quotes at all. If the value of $var is "1214", the code will output:
1214
require "url";
- This language construct will include the page between the quotes. Can NOT be used with dynamic pages, e.g.require("main.php?username=SomeUser");
would not work. This is not a function but a language construct.date("Date/time format");
- Function which returns a date from a Unix Timestamp - where H is the hour, i is the minutes, s is the seconds, d is the day, m is the month and Y is the year in four digits - e.g.date("H:i:s d/m/Y");
would return12:22:01 10/08/2006
on 10th August 2006 at 12:22:01.unlink("filename");
- Function which deletes the file specified in filename.
PHP 4
[編輯]Basic Level
[編輯]<?php
$variable1 = 'beginning';
//This is a comment after a variable being defined
if ($variable1 == 'beginning') {
//If is a test to see if a variable has certain
//value and initiates the wanted sequences if true
echo 'Hello World!';
//The echo displays to the page
}
?>
OOP
[編輯]Include OOP based examples, made by experienced developer
PHP 5 Only
[編輯]Basic Level
[編輯]Basics, working only on PHP 5.
file_put_contents("filename", "Text to save");
- Functions which saves the text specified in Text to save to the file specified in filename. Will overwrite existing file contents unless another parameter FILE_APPEND is added.
E.g. file_put_contents("filename", "Text to save");
will write Text to save to filename, but will overwrite existing text whereas file_put_contents("filename", "Text to save", FILE_APPEND);
will write Text to save to filename, but will not overwrite existing text (instead it appends).
OOP
[編輯]- Input validation by Kgrsajid.
- Advanced Input validation by nemesiskoen.
Editors
[編輯]For reviews of numerous PHP editors, see PHP-editors.
- Bluefish - PHP Open Source editor (Linux/Unix)
- Dreamweaver - PHP/HTML/CFML Integrated Developer Environment (Windows/Mac OS X)
- DzSoft PHP Editor - 30 day trial available. IDE designed for PHP with syntax checking and running on the script (requires PHP to be installed)
- SciTE - Scintilla-based editor (Windows/Linux)
- KDevelop - Integrated Development Environment (Linux/Unix)
- Kate - Supports a variety of network protocols transparently, kde style - lighter than KDevelop (Linux/Unix)
- PHP Designer - Free (deprecated) PHP editor (Windows)
- TextPad - A robust text editor, highlights PHP Syntax (Windows)
- NetBeans PHP IDE - NetBeans PHP IDE (Windows/Linux/Mac OS X)
- PHPEclipse - PHP module for Eclipse IDE (Windows/Linux/Mac OS X)
- Trustudio - PHP IDE built on Eclipse (Windows/Linux/Mac OS X)
- PHPRunner - Wizard-based interface development (Windows)
- Taco HTML Edit - PHP/HTML editor with live previews of generated pages (Mac OS X)
- gPHPEdit - PHP/HTML For the GNOME Desktop (Linux)
- Zend - Zend Development Enviroment by Zend - The PHP company (Windows/Linux/Mac OS X)
- PHPEdit - A nice PHP Editor for Windows (Windows)
- Dev-PHP - Full-featured IDE for PHP (Windows)
- Jedit - Open Source editor that has many PHP-centric plugins available such as error checking, ftp & structure browser (Windows/Linux/Mac OS X)
- TextMate - Programmers code and markup editor with support for PHP (Mac OS X)
- VIM - Terminal-based text editor, supporting PHP markup (Most platforms) (GPL License)
- Emacs - Emacs is the extensible, customizable, self-documenting real-time display editor. Supports PHP by php-mode.el (Most platforms) (GPL License)
- Quanta Plus - KDE based editor, supporting PHP and other markup languages (Linux) (GPL License)
- Homesite - Code-centric editor with PHP 4 support (Windows)
- Weaverslave - Open source editor, supporting PHP and other markup languages (Open Source) (Windows) (Custom License)
- Notepad - The built-in editor in Windows.
- Notepad++ - A great upgrade to Notepad, brings many new features.
- Enginsite - Fully loaded with just about everything that you would expect from a modern software development environment (Windows)
- NuSphere PhpED - PHP IDE with support for HTML, CSS, XML, SMARTY, XHTML and other with a powerful debugger. (Windows/Linux)
- Komodo IDE - IDE for PHP, Perl, Python, Ruby, Javascript and others. (Windows/Linux/Mac OS X)
Resources
[編輯]- From C/C++ to PHP Most people program in C++ but not in PHP. This tutorial will explain the important differences.
- [1] Hudzilla.org - Paul Hudson's excellent beginner-expert guide to PHP.
- PHP Tutorial - educational resource for beginners
- W3Schools - Quick start with PHP for beginners.
- The Oracle+PHP Cookbook - Explore a broad range of HowTos for leveraging Oracle's PL/SQL APIs in PHP applications.
- PHP.net - The PHP website. This is where you go to both get PHP and to read the documentation.
- The PHP Manual - Extensive information about PHP.
- PHP Developers Network - Network of PHP-resource driven websites.
- PHP Book Chapters - Sample PHP books chapters, read online.
- Computer-Books.us - A collection of PHP books available for free download.
- PHP Tutorials
- PHPFreaks.com - Learn PHP, PHP Tutorials / Howto, code examples, PHP scripts.
- PHP-Help.net: PHP codes, PHP scripts, PHP examples - PHP help, PHP codes examples, PHP scripts.
- PHP Documentation - Searchable documentation with user comments.
- PHP Books - A large collection of PHP related books.
- PHPSC - PHP Security Consortium. Guides, etc. on security in PHP code.
- Programmabilities.com - PHP scripts and tutorials.
- PHP-Resources.org - Tutorials, docs, newgroups and scripts.
- PHP Resources - Resources and techniques.
- PHP Resource Index - Another nice PHP portals for various PHP resources.
- PHP Builder - A website for PHP news, articles, code library, forums, etc.
- PHPPatterns - Raising awareness and bringing PHP to the Enterprise Creating understanding of PHP's Advanced Capabilities.
- Good PHP Tutorials - A categorized collection of PHP tutorials.
- Mojavi - One of the most popular MVC framework of PHP.
- PHP Web Application Component Toolkit http://phpwact.org/ - It's a wiki.
- Hotscripts.com :: PHP - A very good PHP portal.
- PHP MySQL Tutorial - Very good beginners tutorial.
- Notepad++ - Very simple yet effective source code editor. Supports highlighting and folding.
- EvilWalrus.org - Hundreds of user-contributed scripts and articles; tagged and searchable.
- NuTutorials PHP Section - Categorized tutorials (~500) for PHP.
- Beginners PHP - Tutorials and resources.
- Symfony - Advanced MVC framework for PHP.
- SELFPHP - A very good PHP portal. Searchable documentation with examples, PHP Code Book, Code library, forums and Tutorials.
- PHP Books - A large collection of PHP books.
- PHP Screencast Tutorials - Screencasts, PDF, and source code for learning PHP.
- PHP Sample Code on Zedwood - Generate PDFs, XLS files, CSVs, parse xml, analyze mp3s all with php
- PHPIndonesia.com - The leading PHP knowledge base in Indonesia that using Wiki format
- getphp.net - PHP and MySQL resources.
Contributors
[編輯]- Jatkins: PHP 4 & 5 examples, and PHP 5 only examples.
- Douglas Clifton: New editor. Hoping to add more soon!
- James Booker: Minor corrections. Hoping to add more content in time.
- Spoom: Original for and switch...case articles, various reformatting and additions.
- IBB: See profile.
- Kander: Minor edits to the PHP and MySQL section.
- Qrc: Started initial page for Configuration:Register Globals.
- Bumppo: Started object-oriented PHP section
- programmabilities: Minor edits.
- ahc: Significant editing to existing sections.
- Liu Chang: Added "Setting up PHP" section. Hoping to add more in time
- Monkeymatt: Fixed some typos, fixed the templating section.
- Charles Iliya Krempeaux: Added PHP CLI section. Minor cleanups on existing sections. Added PHP-GTK section.
- scorphus: Fixes in installation procedures on Debian systems (to conform standards - we now use aptitude)
- immortalgeek: Added some php web links to Resource section.
- Wykis: Working on Smarty section, foreach, arrays, sessions, all basic programming
- Bolo: working on Flat Frog section.
- KGR Sajid: PHP5 editor. Also edited some other minor things.
- banzaimonkey: Formatting changes and editing.
- Meemo: Some small edits, fixing a few scripts and the spelling of Rumpelstiltskin. ;)
- Justin Kestelyn: Added a link in Resources.
- Sam Wilson: Elaboration on session fixation.
- http://www.zeuscoder.com -PHP, MySQL Training and development.