Documentos de Académico
Documentos de Profesional
Documentos de Cultura
A. What is PHP?
Rasmus Lerdorf released the first version of PHP in 1995. In a little over a decade since, it has progressed
through five versions (the sixth is in development) and has become one of the most popular scripting
languages on the web.
PHP is an embeddable, server-side scripting language. What, exactly, does that mean, and how does it
make PHP different from HTML or JavaScript? Let's examine that:
1. PHP is embeddable
This simply means that PHP can be mixed in with your HTML. Opening and closing tags enclose the PHP
script and identify it as something different from HTML. We'll show how this is done in a minute.
2. PHP is a server-side language
When you surf the web, there is an invisible electronic conversation going on between your browser and
the web sites you visit. The two "speakers" in this conversation are your browser, referred to as the
client, and the computer which hosts the web site you're visiting, referred to as the web server.
The conversation takes the form of requests from the client (your browser) and responses from the web
server. These are called HTTP requests and responses. HTTP stands for "hypertext transfer protocol." All
of this is just a technical way of saying that your browser and the web server follow a strict, standardized
method of communicating. (Refer to introductory notes)
When we say PHP is a server-side language, we mean that all of its instructions are carried out on the
web server, before the page is served to your browser. By contrast, JavaScript is a client-side language.
All of the work of a JavaScript is carried out by your browser, after the HTML is served to it.
a. PHP vs. HTML
A fast food restaurant provides a good analogy for the difference between static HTML and PHP.
HTML pages are made up ahead of time and stored on the server. When the customer (client, your
browser) requests an HTML page all the server has to do is grab a pre-made page and hand it over.
By contrast, PHP page unlike the HTML, isn't made up until the customer orders it. The server is notified
of the special order and serves it to the customer.
To embed PHP code in an HTML document, simply include the code within the opening and closing tags,
like this:
This example illustrates PHP used inline. That means that it is buried within the HTML. The opening and
closing tags mark where we enter or exit PHP mode.
2. Identifying a document that contains PHP with the .php extension
The opening and closing tags identify PHP code within the document, but the server must have some
way of knowing which documents contain PHP code. In technical terms, examining a document for
programming code and executing it is called parsing the document.
Web servers don't generally parse pages with the .htm or .html extension. They just send them,
unexamined, to the browser. A server can be configured to parse every document, but it slows the
server; instead, most are configured to parse documents with particular extensions, in this case, the
.php extension.