PHP Code Islands

Use PHP code islands to indicate where you want your PHP code to appear in the page.  Markers indicate where an  island begins, and where it ends.

An empty code island, with no code inside, looks like this:

<?php ?>

Or like this, spanning multiple lines:

<?php

?>

The screenshot below shows how Dreamweaver code view renders PHP code island markers in red (syntax highlighting):

In Design View, Dreamweaver displays a symbol indicating the PHP code island:

How PHP Code Islands Work

  • PHP code island markers define a block of PHP code that the web server will process.
  • A typical PHP page has one or several blocks of PHP code, mixed in with static HTML.
  • PHP code islands exist outside the static HTML.
  • The server never sends the code markers themselves, nor the PHP code itself.
  • PHP code may generate dynamic text content, including HTML tags (and CSS, and JavaScript, etc.)
  • Dynamic content will be sent to users, along with — and indistinguishable from — static HTML content

Code islands exist for one purpose: so you can write PHP code in order to make the web server do things.

Where Do Code Islands Go?

In PHP pages that combine HTML and PHP, use code islands where you want PHP output to appear in the page. This could be literally anywhere in the page, depending on what you are doing.

If a code island has no output, it commonly appears at the very top of the page, because the PHP code is doing something that will be used in subsequent code islands.