<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/tutorial.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'tutorial.firstpage.php',
    1 => 'Your first PHP-enabled page',
    2 => 'Your first PHP-enabled page',
  ),
  'up' => 
  array (
    0 => 'tutorial.php',
    1 => 'A simple tutorial',
  ),
  'prev' => 
  array (
    0 => 'tutorial.php',
    1 => 'A simple tutorial',
  ),
  'next' => 
  array (
    0 => 'tutorial.useful.php',
    1 => 'Something Useful',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'chapters/tutorial.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="tutorial.firstpage" class="section">
   <div class="info"><h1 class="title">Your first PHP-enabled page</h1></div>
   <p class="simpara">
    This tutorial assumes PHP is already installed.
    Installation instructions can be found on the
    <a href="https://www.php.net/downloads.php" class="link external">&raquo;&nbsp;download page</a>.
   </p>
   <p class="para">
    Create a file named <var class="filename">hello.php</var>
    with the following content:
   </p>
   <p class="para">
    <div class="example" id="example-1">
     <div class="info"><p><strong>Example #1 Our first PHP script: <var class="filename">hello.php</var></strong></p></div>
     <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">"Hello World!"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
     </div>

     <div class="example-contents"><p>
      Using your terminal, navigate to the directory containing this file and
      start a development server with the following command:
     </p></div>
     <div class="example-contents">
<div class="shellcode"><pre class="shellcode">php -S localhost:8000</pre>
</div>
     </div>

     <div class="example-contents"><p>
      Use your browser to access the file with your web server&#039;s URL, ending
      with the <code class="literal">/hello.php</code> file reference.
      According to the previous command executed, the URL will be
      <code class="literal">http://localhost:8000/hello.php</code>.
      If everything is configured correctly, this file will be parsed by PHP
      and you will see the &quot;Hello World!&quot; output displayed in your browser.
     </p></div>
     <div class="example-contents"><p>
      PHP can be embedded within a normal HTML web page. That means inside your HTML document
      you can write the PHP statements, as demonstrated in the following example:
     </p></div>
     <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">&lt;!DOCTYPE html&gt;<br />&lt;html&gt;<br />    &lt;head&gt;<br />        &lt;title&gt;PHP Test&lt;/title&gt;<br />    &lt;/head&gt;<br />    &lt;body&gt;<br />        <span style="color: #0000BB">&lt;?php </span><span style="color: #007700">echo </span><span style="color: #DD0000">'&lt;p&gt;Hello World&lt;/p&gt;'</span><span style="color: #007700">; </span><span style="color: #0000BB">?&gt;<br /></span>    &lt;/body&gt;<br />&lt;/html&gt;</span></code></div>
     </div>

     <div class="example-contents"><p>
      This will result in the following output:
     </p></div>
     <div class="example-contents screen">
<div class="cdata"><pre>
&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;PHP Test&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;p&gt;Hello World&lt;/p&gt;
    &lt;/body&gt;
&lt;/html&gt;
</pre></div>
     </div>
    </div>
   </p>
   <p class="para">
    This program is extremely simple and you really did not need to use
    PHP to create a page like this. All it does is display:
    <code class="literal">Hello World</code> using the PHP <span class="function"><a href="function.echo.php" class="function">echo</a></span>
    statement. Note that the file <em>does not need to be executable</em>
    or special in any way. The server finds out that this file needs to be interpreted
    by PHP because you used the &quot;.php&quot; extension, which the server is configured
    to pass on to PHP. Think of this as a normal HTML file which happens to have
    a set of special tags available to you that do a lot of interesting things.
   </p>

   <p class="para">
    The point of the example is to show the special PHP tag format.
    In this example we used <code class="literal">&lt;?php</code> to indicate the
    start of a PHP tag. Then we put the PHP statement and left PHP mode by
    adding the closing tag, <code class="literal">?&gt;</code>. You may jump in
    and out of PHP mode in an HTML file like this anywhere you want.  For more
    details, read the manual section on the <a href="language.basic-syntax.php" class="link">
    basic PHP syntax</a>.
   </p>

   <blockquote class="note"><p><strong class="note">Note</strong>: 
    <span class="info"><strong>A Note on Line Feeds</strong><br /></span>
    <p class="para">
     Line feeds have little meaning in HTML, however it is still a good idea
     to make your HTML look nice and clean by putting line feeds in.  A
     linefeed that follows immediately after a closing
     <code class="literal">?&gt;</code> will be removed by PHP.  This can be extremely
     useful when you are putting in many blocks of PHP or include files
     containing PHP that aren&#039;t supposed to output anything.  At the same time
     it can be a bit confusing.  You can put a space after the closing
     <code class="literal">?&gt;</code> to force a space and a line feed to be output,
     or you can put an explicit line feed in the last echo/print from within
     your PHP block.
    </p>
   </p></blockquote>

   <blockquote class="note"><p><strong class="note">Note</strong>: 
    <span class="info"><strong>A Note on Text Editors</strong><br /></span>
    <p class="para">
     There are many text editors and Integrated Development Environments (IDEs)
     that you can use to create, edit and manage PHP files. A partial list of
     these tools is maintained at <a href="http://en.wikipedia.org/wiki/List_of_PHP_editors" class="link external">&raquo;&nbsp;PHP Editors
     List</a>. If you wish to recommend an editor, please visit the above
     page and ask the page maintainer to add the editor to the list.  Having
     an editor with syntax highlighting can be helpful.
    </p>
   </p></blockquote>

   <blockquote class="note"><p><strong class="note">Note</strong>: 
    <span class="info"><strong>A Note on Word Processors</strong><br /></span>
    <p class="para">
     Word processors such as StarOffice Writer, Microsoft Word and Abiword are
     not optimal for editing PHP files.  If you wish to use one for this
     test script, you must ensure that you save the file as <em>plain
     text</em> or PHP will not be able to read and execute the script.
    </p>
   </p></blockquote>

   <p class="para">
    Now that you have successfully created a working PHP script, it is
    time to create the most famous PHP script!  Make a call to the
    <span class="function"><a href="function.phpinfo.php" class="function">phpinfo()</a></span> function and you will see a lot of useful
    information about your system and setup such as available
    <a href="language.variables.predefined.php" class="link">predefined variables</a>,
    loaded PHP modules, and <a href="configuration.php" class="link">configuration</a>
    settings. Take some time and review this important information.
   </p>
   <p class="para">
    <div class="example" id="example-2">
     <div class="info"><p><strong>Example #2 Get system information from PHP</strong></p></div>
     <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />phpinfo</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
     </div>

    </div>
   </p>
  </div><?php manual_footer($setup); ?>