Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
356 changes: 173 additions & 183 deletions chapters/intro.xml
Original file line number Diff line number Diff line change
@@ -1,203 +1,193 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<chapter xml:id="introduction" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<chapter xml:id="introduction"
xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink">

<info>
<titleabbrev>Introduction</titleabbrev>
<title>What is PHP and what can it do?</title>
<title>What is PHP and what can it do?</title>
<titleabbrev>Introduction</titleabbrev>
</info>

<!-- ================================
SECTION: What is PHP?
================================ -->
<section xml:id="intro-whatis" annotations="chunk:false">
<info><title>What is PHP?</title></info>
<para>
<acronym>PHP</acronym> (recursive acronym for <emphasis>PHP: Hypertext
Preprocessor</emphasis>) is a widely-used open source general-purpose
scripting language that is especially suited for web
development and can be embedded into HTML.
</para>
<para>
Nice, but what does that mean? An example:
</para>
<para>
<info>
<title>What is PHP?</title>
</info>

<para>
<acronym>PHP</acronym> (a recursive acronym for
<emphasis>PHP: Hypertext Preprocessor</emphasis>)
is a widely used open-source general-purpose scripting language
especially suited for web development, and it can be embedded directly into HTML.
</para>

<para>
What does that mean in practice? Consider the following example:
</para>

<example>
<info><title>An introductory example</title></info>
<programlisting role="php">
<![CDATA[
<info><title>An introductory example</title></info>
<programlisting role="php"><![CDATA[
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
</head>
<body>
<head>
<title>Example</title>
</head>
<body>

<?php
echo "Hi, I'm a PHP script!";
?>
<?php
echo "Hi, I'm a PHP script!";
?>

</body>
</body>
</html>
]]>
</programlisting>
]]></programlisting>
</example>
</para>
<para>
Instead of lots of commands to output HTML (as seen in C or Perl),
PHP pages contain HTML with embedded code that does
<replaceable>something</replaceable> (in this case, output <computeroutput>Hi, I'm a PHP script!</computeroutput>).
The PHP code is enclosed in special <link
linkend="language.basic-syntax.phpmode">start and end processing
instructions <code>&lt;?php</code> and <code>?&gt;</code></link>
that allow jumping in and out of <quote>PHP mode.</quote>
</para>
<para>
What distinguishes PHP from something like client-side JavaScript
is that the code is executed on the server, generating HTML which
is then sent to the client. The client would receive
the results of running that script, but would not know
what the underlying code was. A web server can even be configured
to process all HTML files with PHP, and then there's no
way that users can tell that PHP is being used.
</para>
<para>
The best part about using PHP is that it is extremely simple
for a newcomer, but offers many advanced features for
a professional programmer. Don't be afraid to read the long
list of PHP's features. With PHP, almost anyone can get up and running and be
writing simple scripts in no time at all.
</para>
<para>
Although PHP's development is focused on server-side scripting,
much more can be done with it. Read on, and see more in the
<link linkend="intro-whatcando">What can PHP do?</link> section,
or go right to the <link linkend="tutorial">introductory
tutorial</link> to jump straight to learning about web programming.
</para>

<para>
Instead of using many commands to output HTML (as in languages such as C or Perl),
PHP pages contain regular HTML with embedded code that performs
<replaceable>actions</replaceable> (in this case, outputting
<computeroutput>Hi, I'm a PHP script!</computeroutput>).
The PHP code is enclosed within special processing instructions
<code>&lt;?php</code> and <code>?&gt;</code> that allow switching into and out of
<quote>PHP mode</quote>.
</para>

<para>
Unlike client-side JavaScript, PHP code is executed on the server,
generating HTML that is then sent to the client. The client sees
only the final output and not the underlying PHP code.
A web server can even be configured to process all HTML files through PHP,
making it impossible for users to know that PHP is being used.
</para>

<para>
One advantage of PHP is that it is extremely simple for beginners
while still offering advanced features for experienced developers.
With PHP, almost anyone can begin writing useful scripts quickly.
</para>

<para>
Although PHP’s primary focus is server-side scripting,
it is capable of much more. You can read more in the
<link linkend="intro-whatcando">What can PHP do?</link> section,
or jump straight into the <link linkend="tutorial">introductory tutorial</link>
to start learning web programming.
</para>

</section>

<!-- ================================
SECTION: What can PHP do?
================================ -->
<section xml:id="intro-whatcando" annotations="chunk:false">
<info><title>What can PHP do?</title></info>
<para>
Anything. PHP is mainly focused on server-side scripting,
so it can do anything any other CGI program can do, such
as collect form data, generate dynamic page content, or
send and receive cookies. But PHP can do much more.
</para>
<para>
There are two main areas where PHP scripts are used.
<info>
<title>What can PHP do?</title>
</info>

<para>
PHP is capable of performing anything that other CGI programs can do,
such as collecting form data, generating dynamic page content,
or sending and receiving cookies. However, PHP goes far beyond these capabilities.
</para>

<para>
PHP scripts are mainly used in two primary areas:
</para>

<itemizedlist>
<listitem>
<simpara>
Server-side scripting. This is the most widely used
and main target field for PHP. Three things are needed
to make this work: the PHP parser (CGI or server
module), a web server, and a web browser. All these can
run on a local machine in order to just experiment
with PHP programming. See the
<link linkend="install">installation instructions</link>
section for more information.
</simpara>
</listitem>
<listitem>
<simpara>
Command line scripting. A PHP script can be run
without any server or browser, only the
PHP parser is needed to use it this way.
This type of usage is ideal for scripts regularly
executed using <command>cron</command> (on Unix or macOS) or Task Scheduler (on
Windows). These scripts can also be used for simple text
processing tasks. See the section about
<link linkend="features.commandline">Command line usage of PHP</link>
for more information.
</simpara>
</listitem>
<listitem>
<para>
<emphasis>Server-side scripting.</emphasis>
This is PHP’s most common use case. To run server-side scripts,
you need three components: the PHP parser (as a CGI binary or a server module),
a web server, and a web browser. All of these can run locally for testing and development.
For details, refer to the <link linkend="install">installation instructions</link>.
</para>
</listitem>

<listitem>
<para>
<emphasis>Command-line scripting.</emphasis>
PHP scripts can also run on the command line, without any web server or browser.
This is ideal for scripts executed using tools such as <command>cron</command>
on Unix/macOS or Task Scheduler on Windows.
PHP is also suitable for text-processing tasks.
See <link linkend="features.commandline">Command line usage of PHP</link> for more information.
</para>
</listitem>
</itemizedlist>
</para>
<para>
PHP can be <link linkend="install">used</link> on all major operating systems, including
Linux, many Unix variants (including HP-UX, Solaris and OpenBSD),
Microsoft Windows, macOS, RISC OS, and probably others.
PHP also has support for most of the web servers today. This
includes Apache, IIS, and many others. And this includes any
web server that can utilize the FastCGI PHP binary, like lighttpd
and nginx. PHP works as either a module, or as a CGI processor.
</para>
<para>
So with PHP, developers have the freedom of choosing an operating
system and a web server. Furthermore, they also have the choice
of using procedural programming or object-oriented
programming (OOP), or a mixture of them both.
</para>
<para>
PHP is not limited to outputting HTML. PHP's abilities include
outputting rich file types, such as images or PDF files, encrypting data,
and sending emails. It can also output easily any text, such as JSON
or XML. PHP can autogenerate these files, and save them in the
file system, instead of printing it out, forming a server-side cache for
dynamic content.
</para>
<para>
One of the strongest and most significant features in PHP is its
support for a <link linkend="refs.database">wide range of databases</link>.
Writing a database-enabled web page is incredibly simple using one of
the database specific extensions (e.g., for <link linkend="book.mysqli">mysql</link>),
or using an abstraction layer like <link linkend="book.pdo">PDO</link>, or connect
to any database supporting the Open Database Connection standard via the
<link linkend="book.uodbc">ODBC</link> extension. Other databases may utilize
<link linkend="book.curl">cURL</link> or <link linkend="book.sockets">sockets</link>,
like CouchDB.
</para>
<para>
PHP also has support for talking to other services using protocols
such as LDAP, IMAP, SNMP, NNTP, POP3, HTTP, COM (on Windows) and
countless others. It can also open raw network sockets and
interact using any other protocol. PHP has support for the WDDX
complex data exchange between virtually all Web programming
languages. Talking about interconnection, PHP has support for
instantiation of Java objects and using them transparently
as PHP objects.
</para>
<para>
PHP has useful <link linkend="refs.basic.text">text processing</link> features,
which includes the Perl compatible regular expressions (<link linkend="book.pcre">PCRE</link>),
and many extensions and tools to <link linkend="refs.xml">parse and access XML documents</link>.
PHP standardizes all of the XML extensions on the solid base of <link linkend="book.libxml">libxml2</link>,
and extends the feature set adding <link linkend="book.simplexml">SimpleXML</link>,
<link linkend="book.xmlreader">XMLReader</link> and <link linkend="book.xmlwriter">XMLWriter</link> support.
</para>
<para>
And many other interesting extensions exist, which are categorized both
<link linkend="extensions">alphabetically</link> and by <link linkend="funcref">category</link>.
And there are additional <link linkend="install.pecl.intro">PECL extensions</link> that may or may not be documented
within the PHP manual itself, like <link xlink:href="&url.xdebug;">XDebug</link>.
</para>
<para>
This page is not enough to list all
the features and benefits PHP can offer. Read on in
the sections about <link linkend="install">installing
PHP</link>, and see the <link linkend="funcref">function
reference</link> part for explanation of the extensions
mentioned here.
</para>

<para>
PHP runs on all major operating systems, including Linux, numerous Unix variants
(such as HP-UX, Solaris, and OpenBSD), Microsoft Windows, macOS, and others.
It also supports a wide range of web servers including Apache, IIS, lighttpd, and nginx.
PHP can operate either as a module or as a CGI/FastCGI processor.
</para>

<para>
PHP gives developers the freedom to choose their operating system,
web server, and programming paradigm. You may write procedural code,
object-oriented programs, or a combination of both.
</para>

<para>
PHP is not limited to generating HTML. It can create images, PDF files,
and other rich content types; encrypt data; and send emails.
It can output text formats such as XML or JSON and can generate files for
server-side caching.
</para>

<para>
One of PHP’s strongest features is its support for a
<link linkend="refs.database">wide range of databases</link>.
Using extensions such as <link linkend="book.mysqli">MySQLi</link>,
abstraction layers such as <link linkend="book.pdo">PDO</link>,
or the <link linkend="book.uodbc">ODBC</link> extension,
making database-enabled web pages becomes straightforward.
Other databases can be accessed using <link linkend="book.curl">cURL</link>
or <link linkend="book.sockets">sockets</link>, such as CouchDB.
</para>

<para>
PHP supports communication with services using protocols such as LDAP,
IMAP, SNMP, NNTP, POP3, HTTP, COM (on Windows), and more.
It can also open raw network sockets for custom protocols.
PHP supports WDDX for data exchange between different programming languages.
It can instantiate Java objects and interact with them through a PHP interface.
</para>

<para>
PHP includes powerful <link linkend="refs.basic.text">text processing</link> features,
including PCRE-compatible regular expressions
(<link linkend="book.pcre">PCRE</link>)
and multiple extensions for working with XML. XML functionality is built on
<link linkend="book.libxml">libxml2</link> and includes
<link linkend="book.simplexml">SimpleXML</link>,
<link linkend="book.xmlreader">XMLReader</link>,
and <link linkend="book.xmlwriter">XMLWriter</link>.
</para>

<para>
Many other useful extensions exist, listed both
<link linkend="extensions">alphabetically</link>
and by <link linkend="funcref">category</link>.
Additional extensions are available through PECL
(<link linkend="install.pecl.intro">PECL extensions</link>),
including tools such as Xdebug.
</para>

<para>
This chapter cannot list every feature PHP offers. Read the sections on
<link linkend="install">installing PHP</link> and consult the
<link linkend="funcref">function reference</link> for more details
about the features and extensions mentioned here.
</para>

</section>

</chapter>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
</chapter>
Loading