Академический Документы
Профессиональный Документы
Культура Документы
PHP
HomeBuildingPromotionIncomeAdvancedToolsResources
What is PHP?
PHP, which stands for "Hypertext Preprocessor", is a server-side, HTML
embedded scripting language used to create dynamic Web pages. Much of its syntax
is borrowed from C, Java and Perl with some unique features thrown in. The goal of
the language is to allow Web developers to write dynamically generated pages
quickly.
In an HTML page, PHP code is enclosed within special PHP tags. When a visitor opens
the page, the server processes the PHP code and then sends the output (not the PHP
code itself) to the visitor's browser. It means that, unlike JavaScript, you don't have
to worry that someone can steal your PHP script.
PHP offers excellent connectivity to many databases including MySQL, Informix,
Oracle, Sybase, Solid, PostgreSQL, and Generic ODBC. The popular PHP-MySQL
combination (both are open-source products) is available on almost every UNIX host.
Being web-oriented, PHP also contains all the functions to do things on the Internet -
connecting to remote servers, checking email via POP3 or IMAP, url encoding, setting
cookies, redirecting, etc.
• File name:
You should save your file with the extension .php (earlier versions used the
extensions .php3 and .phtml).
• Comments:
// This comment extends to the end of the line.
/* This is
a multi-line
comment */
• Escaping from HTML:
A PHP code block starts with "<?php" and ends with "?>". A PHP code block
can be placed anywhere in the HTML document.
• Instruction separation:
Each separate instruction must end with a semicolon. The PHP closing tag (?
>) also implies the end of the instruction.
echo $txt;
?>
</body>
</html>
PHP tutorials
Webmonkey's intro to PHP
This intro tutorial will get you from zero to PHP in no time flat.
PHP Manual
The comprehensive PHP manual from its control center PHP.net.
PHP and MySQL for Dynamic Web Sites: Visual QuickPro
Guide (2nd Edition)
by Larry Ullman
This is a good book for people who already have some
programming background but are just starting out with PHP. The
book is an excellent introduction to not only PHP but also to
MySQL and database designing.
For more books on PHP see Resources: Books on Web Designing.
PHP editor
Zend Studio
A powerful, integrated platform for writing and maintaining PHP applications. It
combines a comprehensive PHP editor with advanced code completion engine and an
integrated debugger to speed up development time of PHP applications. Available for
Windows, Linux and Mac.
/* All form fields are automatically passed to the PHP script through the array
$HTTP_POST_VARS. */
$email = $HTTP_POST_VARS['email'];
$subject = $HTTP_POST_VARS['subject'];
$message = $HTTP_POST_VARS['message'];
/* PHP form validation: the script checks that the Email field contains a valid email
address and the Subject field isn't empty. preg_match performs a regular expression
match. It's a very powerful PHP function to validate form fields and other strings -
see PHP manual for details. */
if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
echo "<h4>Invalid email address</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
} elseif ($subject == "") {
echo "<h4>No subject</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
}
/* Sends the mail and outputs the "Thank you" string if the mail is successfully sent,
or the error string otherwise. */
elseif (mail($email,$subject,$message)) {
echo "<h4>Thank you for sending email</h4>";
} else {
echo "<h4>Can't send email to $email</h4>";
}
?>
</body>
</html>
As you see, the script is simply one if ... elseif ... else statement. At first, it validates
the required form fields. Note that PHP form validation is performed on the server,
after sending all the data. Therefore, it would be a good idea to combine server-side
form validation with PHP and client-side form validation with JavaScript in order to
avoid unnecessary data sending.
If the email address is valid and subject isn't empty, the script sends the mail and
displays the corresponding message. Note how the variable $email is included into
the output string.
You can also use this script to implement the safe "Contact Us" function on your
website. Your visitors will be able to send you a message, but your email address
won't be displayed on the page and spam bots, that parse pages looking for potential
email addresses, won't get it.
Just remove the Email text field from the form and replace the first line of the script
with something like...
$email = 'YourAddr@YourMail.com';
And, of course, you don't need to validate the email address in this case.
• Overview
• Cascading Style Sheets (CSS)
• HTML Frames
• JavaScript
• PHP
• CGI Scripts
• .htaccess file
What's New
Inexpensive Web Hosting
How to choose a fast and reliable service from the bulk of cheap hosting solutions.
PHP has many open-source libraries included with the core build, and many more are
readily available. Extensions exist to help PHP interface with a number of systems,
including IRC, a number of compression formats, and Windows API. Other extensions
exist to let PHP generate file formats on-the-fly, such as a popular extension which
allows PHP to create Macromedia Flash movies.
Since version 3, PHP has integrated object oriented features. Version 5 built substantially
on this limited functionality, and PHP now has robust object oriented capabilities,
including interfaces, exceptions, destructions, and abstracts.
PHP reached wide-spread popularity with version 4, released in 2000. In 2004 PHP 5 was
debuted, and it is now considered one the top languages used for server-side scripting.
No doubt much of its popularity is due to its relative ease to learn, and its notorious
looseness. Arrays and variables in PHP are able to hold any type of object, variables need
not be declared, and the syntax is remarkably simple.
Unlike many languages, such as C# or Perl, which have primarily a following of more
generalist programmers, many PHP programmers know no other language. This
occasionally causes it to be dismissed as a lesser language, but its growing popularity and
the many robust and efficient sites built using it as a structure seem to dispel this myth.
PHP has occasionally been criticized for what are viewed by some as security flaws, in
comparison to languages such as ASP. A lack of easily understandable error messages, a
sometimes overly robust configuration file, and an obviously incomplete set of built-in
functions are also pointed to as areas which could use marked improvement.
Development continues apace, however, and with each successive build, PHP appears to
address more and more of the concerns raised by its open-source community.