FANDOM


This is the page for standard PHP. If you're looking for MediaWiki extensions, please see PHPMediaWiki Code Snippets.

Basic script Edit

Since PHP is embedded in HTML, you first need an HTML script, like this one:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>The title of the page</title>
  </head>
  <body>
    <h1>The page body</h1>
    <p>Some <b>body text</b></p>
  </body>
</html>

PHP is embedded within an HTML page using <?php and ended with ?> tags. The file type must be *.php. Here is an example PHP script:

<?php
echo "Hello, world!";
?>

...and the script embedded in HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>The title of the page</title>
  </head>
  <body>
    <h1>The page body</h1>
    <p>Some <b>body text</b></p>
    <?php
    echo "<p>Hello, world!</p>";
    ?>
  </body>
</html>

Note that PHP is never sent to the web browser itself. Rather, the PHP interpreter reads the PHP between the <?php and ?> tags and turns it into HTML, which is then sent to the browser.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.