All articles

PHP

What Is PHP Code, and What Does It Do on a Website?

Learn what PHP stands for and why a browser can receive HTML produced by PHP rather than the PHP instructions in a file.

Editorial illustration for What Is PHP Code, and What Does It Do on a Website?

PHP is a programming language commonly used to build websites and web applications. PHP code is a set of instructions written in that language. In a website setup that processes PHP, a server runs those instructions and can send their output to a browser. That distinction matters when you encounter a PHP file: the text in the file and the page a visitor receives are not necessarily the same thing.

What does PHP stand for?

PHP stands for PHP: Hypertext Preprocessor. The name repeats its own initials, but it does not change the practical answer: PHP is a programming language used for web development. The PHP manual calls it an “HTML-embedded scripting language,” while MDN describes it as a server-side language that can be embedded into HTML.

“Server-side” tells you where the code runs in the website setup described here. It does not mean every PHP file must be a web page. PHP code can also be executed from the command line. For a beginner looking at a website, though, the useful first question is usually: Am I looking at instructions for producing a response, or at the response itself?

How are PHP code and its output different?

Consider a conceptual example: a PHP file contains an instruction intended to produce an HTML paragraph. The following line describes that instruction in plain language; it is not PHP source code:

Instruction in the PHP file: produce <p>Hello from PHP</p>

If a server is configured to handle the file as PHP and processes an instruction that produces that paragraph, the resulting HTML could be:

<p>Hello from PHP</p>

The two lines share the paragraph text, but they have different roles. The first describes what the server is being asked to produce. The second represents the text that could be included in its response. Neither block claims that a file was executed here. More importantly, the first block is a description, not a PHP example you could copy into a file and run.

This distinction explains why looking at the result alone may not tell you what was written in the PHP file. PHP can be embedded into HTML, and executed PHP can produce generated HTML. But PHP instructions and the HTML they produce are not interchangeable: one belongs to the source being processed; the other can become response data.

Where does the code run?

In the described web-server setup, the server processes the PHP file with a PHP interpreter. The result can form all or part of the response sent to the browser. As Wikipedia’s PHP overview notes, that result need not be HTML; generated HTML is one possible kind of response data.

For the conceptual example above, picture the server handling a file as PHP and using the paragraph produced by its instructions in the response. The browser receives the result, not the PHP source instruction. If you are inspecting a file to learn what a page may show, keep those two views separate: what is written for PHP to execute, and what execution can produce for the browser. The server-configuration assumption matters; this example does not establish what would happen to an arbitrary file on an arbitrary server.

← All articles