INSERT INTO sites(host) VALUES('') 2002: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) 网站价值¥302,938(不含域名),MYIP.CN网站综合数据统计 - 域名,Alexa,PR,反向链接,关键字
  测网速 网站优化诊断 广告招商QQ3066631932 CodeForge最好的源码站!   手机测速 测速APP



sponsored links:
sponsored links:


网站估价:  (注:不包含域名价值,不代表公司价值)


Google Page Rank:
真假PR鉴别:   (提示:若此处显示网站与查询网站不同,则疑为劫持PR)
Sogou Rank:






Name Server:
Whois Server:

Alexa 排名走势数据

流量统计: 当日 一周平均 三个月平均




Alexa 排名走势图

Alexa Reach走势图

域名 Whois 记录

Who is at

The data contained in, Inc.'s WhoIs database,

while believed by the company to be reliable, is provided "as is"

with no guarantee or warranties regarding its accuracy. This

information is provided for the sole purpose of assisting you

in obtaining information about domain name registration records.

Any use of this data for any other purpose is expressly forbidden without the prior written

permission of, Inc. By submitting an inquiry,

you agree to these terms of usage and limitations of warranty. In particular,

you agree not to use this data to allow, enable, or otherwise make possible,

dissemination or collection of this data, in part or in its entirety, for any

purpose, such as the transmission of unsolicited advertising and

and solicitations of any kind, including spam. You further agree

not to use this data to enable high volume, automated or robotic electronic

processes designed to collect or compile this data for any purpose,

including mining this data for your own personal or commercial purposes.

Please note:
the registrant of the domain name is specified

in the "registrant" field. In most cases,, Inc.

is not the registrant of domain names listed in this database.



Registered through:, Inc. (


Domain servers in listed order:

For complete domain details go to:


sponsored links:


国内Ping速度测试      国内TraceRoute路由测试
美国Ping速度测试      美国TraceRoute路由测试

网站关键字指数 (越高越热门)

域名 learnphp-tutorial 其他后缀注册情况   查看更多

后缀 注册时间 到期时间 是否注册


117,203Tutorial | FREE Tutorial | HTML Tutorial | C Tutorial | C++ Tutorial |
25,083EchoEcho.Com - Web Hosting - JavaScript Tutorial - HTML tutorial - CSS
144,902Kolom Tutorial | free template | JavaScript tutorial
59,449Download Free Tutorial For You. Free Tutorial For Any That You Need
821,920Photoshop Tutorial | SEO Resource | Other Free Tutorial Resource- Just
843,270Free typing tutorial - the best online free typing tutorial.
311,031Free Templates | Free Word Press Theme | HTML Tutorial
243,359Tutorial dan trik-tips blog|Tutorial Blogging | Blog Hack | Trik and T
430,228Tutorial Photoshop, Forum Photoshop, Tutorial CSS, Tutorial PHP, HTML,
213,521PHP Tutorial: Free
635,655Free ebook - Visual Basic, Delphi, Java tutorial - free ebook download
485,894The French Tutorial, Learn French for free - Welcome to the French Tut
482,446Tutorial eBook PDF Free Download
718,302ASPThai.Net,ASP,ASP.NET,ASP Tutorial,ASP Example Code,ASP Free Source
957,849SEO Tool and Tutorial, Free Directory List
478,957Tutorial Paradise - Free Video Tutorials
257,597XPloreMagic: Learn Free Magic Tricks Tutorial
708,642Meet the GIMP! The free video tutorial podcast.
437,620Digital camera help free images photography SLR tutorial
0Free Online Tutorial resource Learn it all
91,329Ajax Tutorial Top List - Free tutorials, articles, examples for web 2.
674,252Free SCJP 1.4 Mock exams,OCP 1z0-007 simulator download,Practice e
380,922Tutorial-Index: Online Tutorial Resource | Adobe Photoshop Tutorials
217,222Kumpulan E-Book | Tutorial Komputer | Video Tutorial | Tips & Tric
646,751Free Logo Site - Free Logo Templates and Tutorial
799, | Free Tutorial Game Online | Internet Entertainment | Seo
497,261FreeTemplateSite - Free Photoshop, osCommerce and PHP-Nuke Website Tem | Maya House | Free Tutorials | Animation Tutorial | 3D : Free-Animation-Multimedia-Film-Graphic_Design-Com
206,777Escalight - 3ds Max tutorial, Photoshop, Flash, V-Ray, Blender, Free 3


Title:PHP Tutorial: Free
Description:This website documents Webucator's Courseware Creation System.
Keywords:courseware creation, technical authoring system, documentation system
PHP Tutorial: Free
Enter your search terms
Submit search form
PHP Tutorial
PHP Tutorial
Watch our 3-minute video to find out
how you can learn PHP with a live instructor.
Table of Contents
PHP Basics
How PHP Works
The php.ini File
Basic PHP Syntax
First PHP Script
PHP Operators
Creating Dynamic Pages
Passing Variables via the Query String
Flow Control
Conditional Processing
Working with Conditions
Working with Loops
Indexed Arrays
Working with Indexed Arrays
Associative Arrays
Working with Associative Arrays
Two-dimensional Arrays
Array Manipulation Functions
PHP and HTML Forms
HTML Forms
Processing Form Input
String Manipulation
Formatting Strings
Working with String Manipulation Functions
Magic Quotes
Reusing Code and Writing Functions
Including Files
Adding a Header and Footer
User Functions
Form Processing
Form Validation and Presentation Functions
Managing Data
Querying a Database
Inserting Records
Advantages and Disadvantages of PEAR DB
Creating a Customer Report
Authentication with PHP and SQL
A Database-less Login Form
Authenticating Users
Regular Expressions
Perl-compatible Regular Expression Functions
Regular Expression Syntax
Form Validation Functions with Regular Expressions
Session Control and Cookies
Authentication with Session Control
Sending Email with PHP
Sending a Password by Email
File System Management
Opening a File
Reading from a File
Writing to a File
Writing to a File
File Locking
Uploading Files via an HTML Form
Getting File Information
More File Functions
Directory Functions
Creating a Resume Management Page
Webucator Tutorials
Ajax Tutorial
ColdFusion Tutorial
CSS Tutorial
HTML Tutorial
JavaScript Tutorial
PHP Tutorial
Schema Tutorial
SQL Tutorial
MySQL Tutorial
XML Tutorial
XSL-FO Tutorial
XSLT Tutorial
Web Accessibility Tutorial
Silverlight Tutorial
Java Tutorial
Webucator Resources
Google Analytics Training
Social Media Training
SQL Training
Windows Training
HTML Training
CSS Training
JavaScript Training
Ajax Training
PHP Training
XML Training
Java Training
Dreamweaver Training
Flash Training
Flex Training
Photoshop Training
Captivate Training
SSRS Training
SSAS Training
SSIS Training
Silverlight Training
Project Management Training
Additional Resources
Self-paced Training
PHP Developer
Bookmark this page:
Add To Digg
Add to reddit
Add to Yahoo! My Web
Add To
Add to Stumble Upon
Add to Spurl
Add to Furl
Add to Ma.gnolia
Add to Slashdot
Add to Mister Wong
PHP Basics
In this lesson of the PHP tutorial, you will learn...
How PHP works.
To write a simple PHP page.
To understand and work with simple PHP variables.
To use PHP operators.
To pass values from one page to another via the URL.
How PHP Works
When a user navigates in her browser to a page that ends with a .php extension, the request is sent to a web server, which directs the request to the PHP interpreter.
As shown in the diagram above, the PHP interpreter processes the page, communicating with file systems, databases, and email servers as necessary, and then delivers a web page to the web server to return to the browser.
The php.ini File
Before we look at PHP syntax, we should briefly mention the php.ini file. This is a plain text file that is used to configure PHP. When the PHP interpreter is started, it reads the php.ini file to determine what settings to use. We will mention this file from time to time throughout the course, but for now, it is enough that you are aware of its existence.
Basic PHP Syntax
PHP Tags
PHP code must be contained in special tags so that the PHP interpreter can identify it. Depending on the PHP configuration, these tags can take several forms:
? gt;
This is the most commonly used (and recommended) form. It is known as the XML style, because it can be used inside of an XML document without causing the document to become poorly formed.
lt;script language="php" gt;
lt;/script gt;
HTML or Script style tags.
? gt;
"Short" tags.
(see footnote)
% gt;
ASP-style tags.
(see footnote)
In this manual, we will use the first form shown as it is the most common and the most portable.
PHP Statements and Whitespace
PHP statements must be inside of PHP tags to be processed by the PHP interpreter. Each PHP statement must end with a semi-colon, which tells the PHP interpreter that the statement is complete. If a semi-colon does not appear at the end of a line, the interpreter will assume that the statement continues onto the next line.
The PHP interpreter condenses all sequential whitespace in PHP scripts to a single whitespace. This convenient feature allows PHP developers to structure their code in a readable format without being concerned about the effects of line breaks and tabs.
PHP has two forms of comments:
Single-line comments begin with a double slash (//).
Multi-line comments begin with "/*" and end with "*/".
// This is a single-line comment
This is
a multi-line
PHP Functions
There are literally hundreds of built-in PHP functions that do everything from returning the current date and time on the server to pulling data out of a database. A function might take zero arguments (e.g, phpinfo(), which returns information on the PHP environment) or it might take several arguments (e.g, mail(), which takes three required and two optional arguments). The syntax for calling a function is straightforward:
The example below shows how the phpinfo() function works.
Code Sample: PhpBasics/Demos/PhpInfo.php
lt;html gt;
lt;head gt;
lt;title gt;PHPINFO lt;/title gt;
lt;/head gt;
lt;body gt;b
//Output information on the PHP environment
? gt;b
lt;/body gt;
lt;/html gt;
Introduction to
PHP functions are well documented at You can quickly look up documentation on a function by going to For example, to see documentation on phpinfo(), go to
(see footnote)
Hello World!
It is an unwritten rule that every programming course must contain a "Hello World!" script. Here it is:
Code Sample: PhpBasics/Demos/HelloWorld.php
lt;html gt;
lt;head gt;
lt;title gt;Hello World! lt;/title gt;
lt;/head gt;
lt;body gt;b
//Write out Hello World!
echo 'Hello World!';
? gt;b
lt;/body gt;
lt;/html gt;
Code Explanation
Notice the following about the above code:
Code between lt;?php and ? gt; is processed by the PHP interpreter.
The echo command is used to print text back to the browser.
This code isn't very exciting. In fact, PHP doesn't buy us anything here as we could have just as easily output the result using straight HTML. There is nothing dynamic about this script. After learning about variables, we'll take a look at some more interesting examples.
PHP variables begin with a dollar sign ($) as shown below.
$var_name = "Value";
Variable Types
Variable Type
whole number
real number
string of characters
true or false
list of items
instance of a class
Variable Names (Identifiers
(see footnote))
consist of letters, digits, underscores and dollar signs
cannot begin with a digit
are case sensitive
Type Strength
PHP is weakly typed, meaning that variables do not need to be assigned a type (e.g, Integer) at the time they are declared. Rather, the type of a PHP variable is determined by the value the variable holds and the way in which it is used.
Hello Variables!
Here is the "Hello World!" script again, but this time we use a variable.
Code Sample: PhpBasics/Demos/HelloVariables.php
b lt;?php
$Greeting = 'Hello World!';
? gt;b
lt;html gt;
lt;head gt;
lt;title gt;b lt;?php echo $Greeting; ? gt;b lt;/title gt;
lt;/head gt;
lt;body gt;b
echo $Greeting;
? gt;b
lt;/body gt;
lt;/html gt;
Code Explanation
This time the string "Hello World!" is stored in the $Greeting variable, which is output in the title and body of the page with an echo command.
Exercise: First PHP Script
Duration: 5 to 10 minutes.
In this exercise, you will write a simple PHP script from scratch. The script will declare a variable called $Today that stores the day of the week.
Open a new document and save it as Today.php in the PhpBasics/Exercises folder.
Declare a variable called $Today that holds the current day of the week as literal text.
Output $Today in the title and body of the page.
Test your solution in a browser. The resulting HTML page should look like this:
Instead of assigning a literal string (e.g, "Monday") to $Today, use the built-in date() function so that the script won't have to be manually updated every day to stay current. For documentation, visit
Where is the solution?
Variable Scope
A variable's scope determines the locations from which the variable can be accessed. PHP variables are either superglobal, global, or local.
Variable Scope
Superglobal variables are predefined arrays, including $_POST and $_GET. They are accessible from anywhere on the page.
Global variables are visible throughout the script in which they are declared. However, they are not visible within functions in the script unless they are re-declared within the function as global variables.
Variables in the function scope are called local variables. Local variables are local to the function in which they are declared.
Again, superglobal variables are predefined arrays, including $_POST and $_GET and are accessible from anywhere on the page. The complete list of superglobals is shown below.
$_GET - variables passed into a page on the query string.
$_POST - variables passed into a page through a form using the post method.
$_SERVER - server environment variables (e.g, $_SERVER['HTTP_REFERER'] returns the URL of the referring page).
$_COOKIE - cookie variables.
$_FILES - variables containing information about uploaded files.
$_ENV - PHP environment variables (e.g, $_ENV['HTTP_HOST'] returns the name of the host server.
(see footnote)
$_REQUEST - variables passed into a page through forms, the query string and cookies.
$_SESSION - session variables.
The elements within superglobal variables can be accessed in three different ways, which the authors of PHP and MySQL Web Development refer to as short style, medium style, and long style.
(see footnote)
Syntax (using $_GET)
Convenient, but it makes it difficult to distinguish superglobal variables from other variables in the code.
Requires register_globals config setting to be on.
Recommended approach.
Happy medium between convenience and clarity.
Not available before v. 4.1.
Inconvenient to type.
Deprecated, but still supported in current versions.
Can be disabled via the register_long_arrays directive in the php.ini file.
Many of these superglobals will be covered later in the course.
Constants are like variables except that, once assigned a value, they cannot be changed. Constants are created using the define() function and by convention (but not by rule) are in all uppercase letters. Constants can be accessed from anywhere on the page.
Variable-Testing and Manipulation Functions
(see footnote)
PHP provides built-in functions for checking if a variable exists, checking if a variable holds a value, and removing a variable.
(see footnote)
Checks to see if a variable exists. Returns true or false.
Removes a variable from memory.
Checks to see if a variable contains a non-empty, non-false value.
PHP Operators
Operators in PHP are similar to those found in many modern C-like programming languages.
Mathematical Operators
$a + $b
$a - $b
$a * $b
$a / $b
$a % $b
String Operators
$a . $b
'Hello' . ' world!'
Assignment Operators
$a = 1;
$c = 'Hello' . ' world!';
Combination Assignment
$a += 1;
$a -= 1;
$a *= 2;
$a /= 2;
$a %= 2;
$a .= ' world!';
Increment By One
Decrement By One
Other Operators
$foo = ($age gt;= 18) ? 'adult' : 'child';
Error Suppression
$a = @(1/0);
Creating Dynamic Pages
Single Quotes vs. Double Quotes
In PHP, for simple strings you can use single quotes and double quotes interchangeably. However, there is one important difference of which you need to be aware. Text within single quotes will not be parsed for variables and escape sequences
(see footnote). Compare the examples below.
Code Sample: PhpBasics/Demos/SingleQuotes.php
lt;html gt;
lt;head gt;
lt;title gt;Single Quotes lt;/title gt;
lt;/head gt;
lt;body gt;b
$person = 'George';
echo '\tHello\n$person!!';
? gt;b
lt;/body gt;
lt;/html gt;
Because of the use of single quotes above, the string "\tHello\n$person!!" will be output literally, as shown below.
Code Sample: PhpBasics/Demos/DoubleQuotes.php
lt;html gt;
lt;head gt;
lt;title gt;Single Quotes lt;/title gt;
lt;/head gt;
lt;body gt;b
$person = "George";
echo "\tHello\n$person!!";
? gt;b
lt;/body gt;
lt;/html gt;
This time, because of the double quotes, the string will be parsed for variables and special characters and will be output as shown below.
To see the effect of the special characters (\n and \t), you will have to view the source of the resulting page.
Passing Variables on the URL
A common way to pass values from the browser to the server is by appending them to the URL as follows:
Syntax amp;who=World
The part of the URL that follows the question mark is called the query string. One or more name-value pairs can be passed to the server in this way. Each name-value pair is separated by an ampersand ( amp;). The processing page can read these name-value pairs and use them to determine its response.
The HTML page below shows an example of how these name-value pairs might be passed.
Code Sample: PhpBasics/Demos/HelloHi.html
lt;html gt;
lt;head gt;
lt;title gt;Preferred Greeting lt;/title gt;
lt;/head gt;
lt;body gt;
Do you prefer a formal greeting or an informal greeting?
lt;ul gt;
lt;li gt; lt;a href="HelloHi.phpb?greet=Hellob" gt;Formal lt;/a gt; lt;/li gt;
lt;li gt; lt;a href="HelloHi.phpb?greet=Hib" gt;Informal lt;/a gt; lt;/li gt;
lt;li gt; lt;a href="HelloHi.phpb?greet=Howdyb" gt;Friendly lt;/a gt; lt;/li gt;
lt;/ul gt;
lt;/body gt;
lt;/html gt;
Code Sample: PhpBasics/Demos/HelloHi.php
b lt;?php
//Assign the passed variable to a variable with
//a more convenient name.
$greeting = $_GET['greet'];
? gt;
lt;html gt;
lt;head gt;
lt;title gt;b lt;?= $greeting ? gt;b World! lt;/title gt;
lt;/head gt;
lt;body gt;b
echo "$greeting World!";
? gt;b
lt;/body gt;
lt;/html gt;
Code Explanation
Notice the following about the code above.
Variable names begin with a dollar sign ($).
Values passed in the query string are part of the $_GET array and can be accessed using the following syntax: $_GET['fieldname'].
A shortcut for echo 'text to print'; is lt;?= 'text to print' ? gt;.
(see footnote)
Exercise: Passing Variables via the Query String
Duration: 10 to 15 minutes.
In this exercise, you will write a script that says hello to different people based on what is passed through the query string.
Open PhpBasics/Exercises/HelloWho.html in your editor. You will see that it is the same as the demo we looked at earlier.
Modify HelloWho.html so that it has four links, each of which passes the name of one of the Beatles (Paul, John, George, and Ringo) to HelloWho.php, which is in the same directory.
Open PhpBasics/Exercises/HelloWho.php in your editor. Modify the code so that it outputs a greeting based on the link clicked on HelloWho.html.
Try it out in your browser.
Change the links so that each Beatle gets a custom greeting (e.g, Howdy Paul, Hi John, Bye George, Hey Ringo).
Where is the solution?
PHP Basics Conclusion
In this lesson of the PHP tutorial, you have learned how to write a simple PHP page, to recognize and look up documentation on PHP functions, to work with variables and to pass variables from one page to another via the query string.
Must be enabled via the short_open_tag
php.ini configuration file directive.
Must be enabled via the asp_tags
php.ini configuration file directive.
Another very good function reference is located at
Variable, function and class names are all identifiers and all follow the rules above, with the exception that function names are not case sensitive.
Which environment variables are available depends on the specific server setup and configuration.
PHP amp; MySQL Web Development, Third Edition, p. 21-22
For a complete list of variable functions see
To output the results of these functions to a browser, use the var_dump() function (e.g. var_dump(isset($a));).
Escape sequences are used for characters that cannot easily be output within strings. Common escape sequences are \n for a newline, \t for a tab, \\ for a backaslash, \" for a double quote, and \$ for a dollar sign.
Many PHP developers feel that it is best practice to avoid using this shortcut syntax for echo. One reason for this is that the shortcut syntax makes the resulting PHP file impossible to parse as XML. Another is that the short_open_tag directive must be turned on for it to work. See
To continue to learn PHP go to the top of this page and click on the next lesson in this PHP Tutorial's Table of Contents.
Last updated on 2009-05-22
All material in this Free is copyright 2010 Webucator.
The purpose of this website is to help you learn PHP on your own and use of the website
implies your agreement to our
PHP Tutorial Terms of Service.
Use of (Website) implies agreement to the following:
Copyright Information
All pages and graphics on Website are the property of Webucator, Inc. unless otherwise specified.
None of the content on Website may be redistributed or reproduced in any way, shape, or form without written
permission from Webucator, Inc.
No Printing or saving of pages or content on Website
This content may not be printed or saved. It is for online use only.
Linking to Website
You may link to any of the pages on Website; however, you may not include the content in a frame or iframe without written permission from Webucator, Inc.
Website is provided without warranty of any kind. There are no guarantees
that use of the site will not be subject to interruptions. All direct or
indirect risk related to use of the site is borne entirely by the user. All code and explanations
provided on this site are provided without warranties to correctness, performance,
fitness, merchantability, and/or any other warranty (whether expressed or
For individual private use only
You agree not to use this online manual to deliver or receive training. If you are delivering or attending a class that is making use of this online manual, you are in violation of our terms of service. Please report any abuse to If you would like to deliver or receive training using this manual, please fill out the form at




桌面软件: MyIP网站信息状态条  WebShot网页快照  SiteMapMaker网站地图生成 
网站信息: Alexa排名查询  PageRank查询/真假PR鉴别/PR劫持检测  外链检查  搜索引擎收录  搜索引擎反向链接  域名注册查询 
网页编辑: 颜色代码选择器  Html特殊符号 
网站调试: 蜘蛛抓取模拟  网站Header信息  网页源代码查看 
代码转换: 火星文查询  繁体/简体转换  Html/js代码转换  Html/UBB代码转换 
友情连接: CodeForge免费源码 PCFans IT资讯 Ngnix Lighttpd GPhone中国    更多... (PR<5自动转内页)
网站地图: 1 2 3 4 5 6 7 8 9 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 250 300 350 400 450 500
免责声明 | 联系我们 | 交换友情链接 | 广告位招商QQ: 1967659002
© 2009 Dev by MYIP Elapsed:197.084ms 黑ICP备09072263号