PHP: Part 1 |
second installment of his extended article introducing
Internet PHP, Paul
Oldham provides an outline guide to forms, functions,
obtaining PHP, and a general index of PHP4 features.
One of the most powerful features of PHP is the
ease with which you can handle forms. If you make
your PHP script the action of the form then all
the fields in the form appear as variables in your
script automatically, ready for you to use. To take
a simple example, suppose you have a page containing
a form such as the one at the top of Figure 4. When
the user clicks on the submit button the page action.php3
will be invoked to process that form. In action.php3
you might have the line of code at the bottom of
Figure 4. As you can see, the input fields “age”
and “name” have automatically become
variables of the script action .php3, with names
“$name” and “$age” ready
for you to do what you like with them (in this case
echoing them as part of the line of HTML).
Your name: <input type=text name=name>
Your age: <input type=text name=age>
<p>Hello <?php echo
$name?>. You are <?php echo $age?>
4 - Forms in PHP - see main text.
The real strength of PHP lies in the extensive range
of built-in functions. Those available include functions
• Access a wide
variety of databases (see below).
the Web server on which the code is running.
a full range of mathematical functions.
arbitrary precision mathematics (log, trig etc).
the date and time and display them in a variety of
external programs on the server and receive the results
a wide variety of operations on the server file system.
functions such as “Get the Internet host name
corresponding to a given IP address”.
Perl-compatible or POSIX-extended regular expressions.
System V semaphores and shared memory o Manipulate
Test a variable’s current type.
to easily exchange data with other applications over
and gunzip files.
Creating powerful Web applications inevitably means
storing and manipulating a lot of data, so the ability
to access databases is vital. PHP includes support,
via function calls, for a wide variety of popular
databases, including Adabase D, dBase, Unix dbm, filePro,
Interbase, Informix, Microsoft SQL Server, mSQL, MySQL,
Oracle, Sybase, PostgreSQL, and Solid. In addition,
any database which supports ODBC, such as Microsoft
Access, can be used. If you’re trying to create
an application which isn’t database-specific
then there are a number of open source abstraction
layers available, including Metabase and phpDB, which
will let you do this painlessly.
The home of PHP on the Web is www.php.net,
and Zend Technologies have their own site at www.zend.com.
These two sites between them contain links to an ever
increasing list of other sites devoted to PHP. PHP
is open source, so you can simply download PHP from
many one of the many mirror sites. PHP also comes
as a package in some Linux distributions.
If the target audience for your PHP-generated pages
is the Web rather than your company intranet, then
a growing number of ISPs can provide you with Web
hosting on servers which support PHP, and an SQL database
back-end, usually MySQL.
PHP4 is significantly faster than PHP3. This improvement
in performance is particularly noticeable with larger
and more complex scripts, and is the result of the
PHPengine having been totally rewritten by Andi Gutmans
and Zeev Suraski. The new Zend engine uses a much
more efficient “compile-then-execute”
method, instead of the “execute-while-parsing”
model used by PHP3. The authors claim the resulting
engine is up to fifty times faster than the PHP3 engine.
Features in PHP4 include:
build process under Unix.
server interface that also supports multi-threaded
http session support.
more powerful configuration system.
PHP4 also provides COM/DCOM support (on Windows only),
allowing you to seamlessly access COM objects and
instantiate them. PHP4 also has a number of additional
optional functions which,with the right libraries,
extend PHP to allow you to process credit cards and
other financial transactions using Verisign Payment
Services, and to handle Internet payments.
Paul Oldham © 2002-2007 All Rights Reserved.
article must not be reproduced without the explicit
permission of the author.
PHP: Part 1 |