Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <nav id="navbar">
  <header>PHP Documentation</header>
  <a href="#Preface" class="nav-link">Preface</a>
  <a href="#What_is_PHP?" class="nav-link">What is PHP?</a>
  <a href="#What_can_PHP_do?" class="nav-link">What can PHP do?</a>
  <a href="#A_simple_tutorial" class="nav-link">A simple tutorial</a>
  <a href="#What_do_I_need?" class="nav-link">What do I need?</a>
  <a href="#Your_first_PHP-enabled_page" class="nav-link">Your first PHP-enabled page</a>
  <a href="#Something_Useful" class="nav-link">Something Useful</a>
  <a href="#Dealing_with_Forms" class="nav-link">Dealing with Forms</a>
  <a href="#Using_old_code_with_new_versions_of_PHP" class="nav-link">Using old code with new versions of PHP</a>
  <a href="#What's_next?" class="nav-link">What's next?</a>
  <a href="#Reference" class="nav-link">Reference</a>
</nav>
<main id="main-doc">
  <section class="main-section" id="Preface">
    <header>Preface</header>
    <p>
    <acronym title="PHP: Hypertext Preprocessor">PHP</acronym>, which stands for "<em>PHP: Hypertext Preprocessor</em>" is a widely-used Open Source general-purpose scripting language that is especially suited for web development and can be embedded into HTML. Its syntax draws upon C, Java, and Perl, and is easy to learn. The main goal of the language is to allow web developers to write dynamically generated web pages quickly, but you can do much more with PHP.</p>
    <p>
    This manual consists primarily of a function reference, but also contains a language reference, explanations of some of PHP's major features, and other supplemental information.</p>
    <p>
    You can download this manual in several formats at <a href="http://www.php.net/download-docs.php" target="_blank">http://www.php.net/download-docs.php</a>.  More information about how this manual is developed can be found in the <a href="http://php.net/manual/en/about.php" target="_blank">'About the manual'</a> appendix. If you are interested in the <a href="http://php.net/manual/en/history.php" target="_blank">history of PHP</a>, visit the relevant appendix.</p>
  </section>
  
  <section class="main-section" id="What_is_PHP?">
    <header>What is PHP?</header>
    <p>
    <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> ( recursive acronym for <em>PHP: Hypertext Preprocessor</em> ) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.</p>
    <p>Nice, but what does that mean? An example:</p>
    <p><b>Example #1 An introductory example</b></p>
    <code><span style="color: #000000">
&lt;!DOCTYPE&nbsp;HTML&gt;<br>&lt;html&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;head&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;Example&lt;/title&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/head&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;body&gt;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">&lt;?php<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"Hi,&nbsp;I'm&nbsp;a&nbsp;PHP&nbsp;script!"</span><span style="color: #007700">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">?&gt;<br></span><br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/body&gt;<br>&lt;/html&gt;</span>
    </code>
    <p>
    Instead of lots of commands to output HTML (as seen in C or Perl),
    PHP pages contain HTML with embedded code that does
    "something" (in this case, output "Hi, I'm a PHP script!").
    The PHP code is enclosed in special start and end processing
    instructions &lt;?php and ?&gt; that allow you to jump into and out of     "PHP mode."</p>
    <p>
    What distinguishes PHP from something like client-side JavaScript
    is that the code is executed on the server, generating HTML which
    is then sent to the client. The client would receive
    the results of running that script, but would not know
    what the underlying code was. You can even configure your web server
    to process all your HTML files with PHP, and then there's really no
    way that users can tell what you have up your sleeve.</p>
    <p>
    The best things in using PHP are that it is extremely simple
    for a newcomer, but offers many advanced features for
    a professional programmer. Don't be afraid reading the long
    list of PHP's features. You can jump in, in a short time, and
    start writing simple scripts in a few hours.</p>
    <p>
    Although PHP's development is focused on server-side scripting,
    you can do much more with it. Read on, and see more in the
    <a href="http://php.net/manual/en/intro-whatcando.php" target="_blank">What can PHP do?</a> section,
    or go right to the <a href="http://php.net/manual/en/tutorial.php" target="_blank">introductory
    tutorial</a> if you are only interested in web programming.</p>
  </section>
  
  <section class="main-section" id="What_can_PHP_do?">
    <header>What can PHP do?</header>
    <p>Anything. PHP is mainly focused on server-side scripting, so you can do anything any other CGI program can do, such as collect form data, generate dynamic page content, or send and receive cookies. But PHP can do much more.</p>
    <p>There are three main areas where PHP scripts are used.</p>
    <ul>
     <li>
       Server-side scripting. This is the most traditional
       and main target field for PHP. You need three things
       to make this work: the PHP parser (CGI or server
       module), a web server and a web browser. You need to
       run the web server, with a connected PHP installation.
       You can access the PHP program output with a web browser,
       viewing the PHP page through the server. All these can
       run on your home machine if you are just experimenting
       with PHP programming. See the
       <a href="http://php.net/manual/en/install.php" target="_blank">installation instructions</a> section for more information.
     </li>
     <li>
       Command line scripting. You can make a PHP script
       to run it without any server or browser.
       You only need the PHP parser to use it this way.
       This type of usage is ideal for scripts regularly
       executed using cron (on *nix or Linux) or Task Scheduler (on
       Windows). These scripts can also be used for simple text
       processing tasks. See the section about
       <a href="http://php.net/manual/en/features.commandline.php" target="_blank">Command line usage of PHP</a> for more information.
     </li>
     <li>
       Writing desktop applications. PHP is probably
       not the very best language to create a desktop
       application with a graphical user interface, but if
       you know PHP very well, and would like to use some
       advanced PHP features in your client-side applications
       you can also use PHP-GTK to write such programs. You also
       have the ability to write cross-platform applications this
       way. PHP-GTK is an extension to PHP, not available in
       the main distribution. If you are interested
       in PHP-GTK, visit <a href="http://gtk.php.net/" target="_blank">its own website</a>.
     </li>
    </ul>
    <p>
    PHP can be <a href="http://php.net/manual/en/install.php" target="_blank">used</a> on all major operating systems, including
    Linux, many Unix variants (including HP-UX, Solaris and OpenBSD),
    Microsoft Windows, macOS, RISC OS, and probably others.
    PHP also has support for most of the web servers today. This
    includes Apache, IIS, and many others. And this includes any
    web server that can utilize the FastCGI PHP binary, like lighttpd
    and nginx. PHP works as either a module, or as a CGI processor.
   </p>
    <p>So with PHP, you have the freedom of choosing an operating system and a web server. Furthermore, you also have the choice of using procedural programming or object oriented programming (OOP), or a mixture of them both.</p>
    <p>
With PHP you are not limited to output HTML. PHP's abilities includes outputting images, PDF files and even Flash movies (using libswf and Ming) generated on the fly. You can also output easily any text, such as XHTML and any other XML file. PHP can autogenerate these files, and save them in the file system, instead of printing it out, forming a server-side cache for your dynamic content.</p>
    <p>
    One of the strongest and most significant features in PHP is its
    support for a <a href="http://php.net/manual/en/refs.database.php" target="_blank">wide range of databases</a>. 
    Writing a database-enabled web page is incredibly simple using one of
    the database specific extensions (e.g., for <a href="http://php.net/manual/en/book.mysqli.php" target="_blank">mysql</a>),
    or using an abstraction layer like <a href="http://php.net/manual/en/book.pdo.php" target="_blank">PDO</a>, or connect
    to any database supporting the Open Database Connection standard via the
    <a href="http://php.net/manual/en/book.uodbc.php" target="_blank">ODBC</a> extension. Other databases may utilize
    <a href="http://php.net/manual/en/book.curl.php" target="_blank">cURL</a> or <a href="http://php.net/manual/en/book.sockets.php" target="_blank">sockets</a>,
    like CouchDB.
   </p>
    <p>
    PHP also has support for talking to other services using protocols such as LDAP, IMAP, SNMP, NNTP, POP3, HTTP, COM (on Windows) and countless others. You can also open raw network sockets and interact using any other protocol. PHP has support for the WDDX complex data exchange between virtually all Web programming languages. Talking about interconnection, PHP has support for instantiation of Java objects and using them transparently as PHP objects.</p>
    <p>
    PHP has useful <a href="http://php.net/manual/en/refs.basic.text.php" target="_blank">text processing</a> features,
    which includes the Perl compatible regular expressions (<a href="http://php.net/manual/en/book.pcre.php" target="_blank">PCRE</a>),
    and many extensions and tools to <a href="http://php.net/manual/en/refs.xml.php" target="_blank">parse and access XML documents</a>.
    PHP standardizes all of the XML extensions on the solid base of <a href="http://php.net/manual/en/book.libxml.php" target="_blank">libxml2</a>,
    and extends the feature set adding <a href="http://php.net/manual/en/book.simplexml.php" target="_blank">SimpleXML</a>,
    <a href="http://php.net/manual/en/book.xmlreader.php" target="_blank">XMLReader</a> and <a href="http://php.net/manual/en/book.xmlwriter.php" target="_blank">XMLWriter</a> support.
   </p>
    <p>
    And many other interesting extensions exist, which are categorized both
    <a href="http://php.net/manual/en/extensions.php" target="_blank">alphabetically</a> and by <a href="http://php.net/manual/en/funcref.php" target="_blank">category</a>.
    And there are additional PECL extensions that may or may not be documented
    within the PHP manual itself, like <a href="http://xdebug.org/" target="_blank">XDebug</a>.
   </p>
    <p>
    As you can see this page is not enough to list all
    the features and benefits PHP can offer. Read on in
    the sections about <a href="http://php.net/manual/en/install.php" target="_blank">installing
    PHP</a>, and see the <a href="http://php.net/manual/en/funcref.php" target="_blank">function
    reference</a> part for explanation of the extensions
    mentioned here.
   </p>
  </section>
  
  <section class="main-section" id="A_simple_tutorial">
    <header>A simple tutorial</header>
    <p>
    Here we would like to show the very basics of PHP in a short, simple
    tutorial. This text only deals with dynamic web page creation with
    PHP, though PHP is not only capable of creating web pages. See
    the section titled <a href="#What_can_PHP_do?">What can PHP do</a> for     more information.
    </p>
    <p>PHP-enabled web pages are treated just like regular HTML pages and     you can create and edit them the same way you normally create regular     HTML pages.</p>
  </section>
  
  <section class="main-section" id="What_do_I_need?">
    <header>What do I need?</header>
    <p>
    In this tutorial we assume that your server has activated support 
    for PHP and that all files ending in <var>.php</var>
    are handled by PHP. On most servers, this is the default extension
    for PHP files, but ask your server administrator to be sure. If
    your server supports PHP, then you do not need to do anything. Just
    create your <var>.php</var> files, put them in your
    web directory and the server will automatically parse them for you.
    There is no need to compile anything nor do you need to install
    any extra tools. Think of these PHP-enabled files as simple HTML
    files with a whole new family of magical tags that let you do all
    sorts of things.</p>
    <p>
    Let us say you want to save precious bandwidth and develop locally.  
    In this case, you will want to install a web server, such as 
    <a href="http://httpd.apache.org/" target="_blank">Apache</a>, and of course 
    <a href="http://www.php.net/downloads.php" target="_blank">PHP</a>. You will most likely 
    want to install a database as well, such as 
    <a href="http://dev.mysql.com/doc/" target="_blank">MySQL</a>.
   </p>
    <p>
    You can either install these individually or choose a simpler way. Our manual has <a href="http://php.net/manual/en/install.php" target="_blank">installation instructions for PHP</a> (assuming you already have some web server set up). If you have problems with installing PHP yourself, we would suggest you ask your questions on our <a href="http://www.php.net/mailing-lists.php"           target="_blank">installation mailing list</a>. If you choose to go on the simpler route, then <a         href="http://wikipedia.org/wiki/List_of_AMP_packages" target="_blank">locate a pre-configured package</a> for your operating system,  which automatically installs all of these with just a few mouse clicks. It is easy to setup a web server with PHP support on any operating system, including MacOSX, Linux and Windows. On Linux, you may find <a href="http://www.rpmfind.net/" target="_blank">rpmfind</a> and <a href="http://rpm.pbone.net/" target="_blank">PBone</a> helpful for locating RPMs. You may also  want to visit <a href="https://packages.debian.org/index" target="_blank">apt-get</a> to find packages for Debian.</p>
  </section>
  <section class="main-section" id="Your_first_PHP-enabled_page">
    <header>Your first PHP-enabled page</header>
    <p>
    Create a file named <var>hello.php</var> and put it
    in your web server's root directory ( <var>DOCUMENT_ROOT</var> ) 
    with the following content:</p>
    <p><b>Example #1 Our first PHP script: <var>hello.php</var></b></p>
    <code><span style="color: #000000">
&lt;html&gt;<br>&nbsp;&lt;head&gt;<br>&nbsp;&nbsp;&lt;title&gt;PHP&nbsp;Test&lt;/title&gt;<br>&nbsp;&lt;/head&gt;<br>&nbsp;&lt;body&gt;<br>&nbsp;<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'&lt;p&gt;Hello&nbsp;World&lt;/p&gt;'</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">?&gt;</span>&nbsp;<br>&nbsp;&lt;/body&gt;<br>&lt;/html&gt;</span>
</code>
    <p>
      Use your browser to access the file with your web server's URL, ending
      with the <em>/hello.php</em> file reference. When developing locally this
      URL will be something like <em>http://localhost/hello.php</em> 
      or <em>http://127.0.0.1/hello.php</em> but this depends on the
      web server's configuration. If everything is configured correctly, this
      file will be parsed by PHP and the following output will be sent to
      your browser:
     </p>
    <pre>&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>
    <p>
    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:
      <em>Hello World</em> using the PHP <a href="http://php.net/manual/en/function.echo.php"
    target="_blank">echo</a>
    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 ".php" 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>
    If you tried this example and it did not output anything, it prompted 
    for download, or you see the whole file as text, chances are that the 
    server you are on does not have PHP enabled, or is not configured properly.
    Ask your administrator to enable it for you using the
    <a href="http://php.net/manual/en/install.php" target="_blank">Installation</a> chapter 
    of the manual. If you are developing locally, also read the
    installation chapter to make sure everything is configured
    properly. Make sure that you access the file via http with the server
    providing you the output. If you just call up the file from your file
    system, then it will not be parsed by PHP. If the problems persist anyway,
    do not hesitate to use one of the many
    <a href="http://www.php.net/support.php" target="_blank">PHP support</a> options.
   </p>
    <p>
    The point of the example is to show the special PHP tag format.
    In this example we used <em>&lt;?php</em> to indicate the
    start of a PHP tag. Then we put the PHP statement and left PHP mode by
    adding the closing tag, <em>?&gt;</em>. 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="http://php.net/manual/en/language.basic-syntax.php" target="_blank">
    basic PHP syntax</a>.
   </p>
    <blockquote><p><strong>Note</strong>: 
    <strong>A Note on Line Feeds</strong>
    </p><p>
     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
     <em>?&gt;</em> 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't supposed to output anything.  At the same time
     it can be a bit confusing.  You can put a space after the closing
     <em>?&gt;</em> 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></blockquote>
    <blockquote><p><strong>Note</strong>: 
    <strong>A Note on Text Editors</strong>
    </p><p>
     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" target="_blank">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></blockquote>
    <blockquote><p><strong>Note</strong>: 
    <strong>A Note on Word Processors</strong>
    </p><p>
     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></blockquote>
    <blockquote><p><strong>Note</strong>: 
    <strong>A Note on Windows Notepad</strong>
    </p><p>
     If you are writing your PHP scripts using Windows Notepad, you will need
     to ensure that your files are saved with the <var>.php</var> extension.
     (Notepad adds a <var>.txt</var> extension to files automatically unless
     you take one of the following steps to prevent it.)  When you save the file and
     are prompted to provide a name for the file, place the filename in quotes 
     (i.e. "<var>hello.php</var>").  Alternatively, you can click on the 
     'Text Documents' drop-down menu in the 'Save' dialog box and change the setting 
     to "All Files". You can then enter your filename without quotes.
    </p></blockquote>
    <p>
    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
    <a href="http://php.net/manual/en/function.phpinfo.php" target="_blank">phpinfo()</a> function and you will see a lot of useful
    information about your system and setup such as available
    <a href="http://php.net/manual/en/language.variables.predefined.php" target="_blank">predefined variables</a>, 
    loaded PHP modules, and <a href="http://php.net/manual/en/configuration.php" target="_blank">configuration</a>
    settings. Take some time and review this important information.
   </p>
    <p><strong>Example #2 Get system information from PHP</strong></p>
    <code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php&nbsp;phpinfo</span><span style="color: #007700">();&nbsp;</span><span style="color: #0000BB">?&gt;</span>
</span></code>
  </section>
  
  <section class="main-section" id="Something_Useful">
    <header>Something Useful</header>
    <p>
    Let us do something more useful now. We are going to check
    what sort of browser the visitor is using.
    For that, we check the user agent string the browser
    sends as part of the HTTP request. This information is stored in a <a href="http://php.net/manual/en/language.variables.php" target="_blank">variable</a>. Variables always start
    with a dollar-sign in PHP. The variable we are interested in right now 
    is <var><a href="http://php.net/manual/en/reserved.variables.server.php" target="_blank">$_SERVER['HTTP_USER_AGENT']</a>var</var>.
   </p>
    <blockquote><p><strong>Note</strong>: 
    </p><p>
     <var><a href="http://php.net/manual/en/reserved.variables.server.php" target="_blank">$_SERVER</a></var> is a 
     special reserved PHP variable that contains all web server information.
     It is known as a superglobal.  See the related manual page on
     <a href="http://php.net/manual/en/language.variables.superglobals.php" target="_blank">superglobals</a>
     for more information.  These special variables were introduced in PHP 
     <a href="http://www.php.net/releases/4_1_0.php" target="_blank">4.1.0</a>.  Before this time, we used
     the older <var>$HTTP_*_VARS</var> arrays instead,
     such as <var>$HTTP_SERVER_VARS</var>.  As of PHP 5.4.0 
     these older variables have been removed.  (See also the note on
     <a href="http://php.net/manual/en/tutorial.oldcode.php" target="_blank">old code</a>.)
    </p></blockquote>
    <p>To display this variable, you can simply do:</p>
    <p><strong>Example #1 Printing a variable (Array element)</strong></p>
    <code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">$_SERVER</span><span style="color: #007700">[</span><span style="color: #DD0000">'HTTP_USER_AGENT'</span><span style="color: #007700">];<br></span><span style="color: #0000BB">?&gt;</span>
</span>
</code>
    <p>
     A sample output of this script may be:
    </p>
    <div class="example-contents">
      <p>Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)</p>
    </div>
    <p>
    There are many <a href="http://php.net/manual/en/language.types.php" target="_blank">types</a> of 
    variables available in PHP.  In the above example we printed 
    an <a href="http://php.net/manual/en/language.types.array.php" target="_blank">Array</a> element. Arrays can be very useful.
   </p>
    <p>
    <var><a href="http://php.net/manual/en/reserved.variables.server.php" target="_blank">$_SERVER</a></var> is just one variable that PHP automatically makes available to you. A list can be seen in the 
    <a href="http://php.net/manual/en/reserved.variables.php" target="_blank">Reserved Variables</a> section of the manual or you can get a complete list of them by looking at the output of the <a href="http://php.net/manual/en/function.phpinfo.php" target="_blank">phpinfo()</a> function used in the example in the previous section.
   </p>
    <p>You can put multiple PHP statements inside a PHP tag and create little blocks of code that do more than just a single echo. For example, if you want to check for Internet Explorer you can do this:</p>
    <p><strong>Example #2 Example using <a href="http://php.net/manual/en/language.control-structures.php" target="_blank">control 
     structures</a> and <a href="http://php.net/manual/en/language.functions.php" target="_blank">functions</a></strong></p>
    <code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">strpos</span><span style="color: #007700">(</span><span style="color: #0000BB">$_SERVER</span><span style="color: #007700">[</span><span style="color: #DD0000">'HTTP_USER_AGENT'</span><span style="color: #007700">],&nbsp;</span><span style="color: #DD0000">'MSIE'</span><span style="color: #007700">)&nbsp;!==&nbsp;</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'You&nbsp;are&nbsp;using&nbsp;Internet&nbsp;Explorer.&lt;br&nbsp;/&gt;'</span><span style="color: #007700">;<br>}<br></span><span style="color: #0000BB">?&gt;</span>
</span>
</code>
    <p>A sample output of this script may be:</p>
    <pre>You are using Internet Explorer.&lt;br /&gt;
</pre>
    <p>
    Here we introduce a couple of new concepts. We have an 
    <a href="http://php.net/manual/en/control-structures.if.php" target="_blank">if</a> statement.
    If you are familiar with the basic syntax used by the C
    language, this should look logical to you. Otherwise, you
    should probably pick up an introductory PHP book and read the first
    couple of chapters, or read the <a href="http://php.net/manual/en/langref.php" target="_blank">Language
    Reference</a> part of the manual.
   </p>
    <p>
    The second concept we introduced was the <a href="http://php.net/manual/en/function.strpos.php" target="_blank">strpos()</a>
    function call. <a href="http://php.net/manual/en/function.strpos.php" target="_blank">strpos()</a> is a function built into
    PHP which searches a string for another string. In this case we are
    looking for <em>'MSIE'</em> (so-called needle) inside
    <var><a href="http://php.net/manual/en/reserved.variables.server.php" target="_blank">$_SERVER['HTTP_USER_AGENT']</a></var> (so-called haystack).  If
    the needle is found inside the haystack, the function returns the position
    of the needle relative to the start of the haystack.  Otherwise, it
    returns <strong><em>FALSE</em></strong>.  If it does not return <strong><em>FALSE</em></strong>, the <a href="http://php.net/manual/en/control-structures.if.php" target="_blank">if</a> expression evaluates to <strong><em>TRUE</em></strong>
    and the code within its {braces} is executed. Otherwise, the code is not
    run. Feel free to create similar examples, 
    with <a href="http://php.net/manual/en/control-structures.if.php" target="_blank">if</a>, 
    <a href="http://php.net/manual/en/control-structures.else.php" target="_blank">else</a>, and other 
    functions such as <a href="http://php.net/manual/en/function.strtoupper.php" target="_blank">strtoupper()</a> and 
    <a href="http://php.net/manual/en/function.strlen.php" target="_blank">strlen()</a>.  Each related manual page contains examples 
    too.  If you are unsure how to use functions, you will want to read both
    the manual page on <a href="http://php.net/manual/en/about.prototypes.php" target="_blank">how to read a
    function definition</a> and the section about  
    <a href="http://php.net/manual/en/language.functions.php" target="_blank">PHP functions</a>.
   </p>
    <p>We can take this a step further and show how you can jump in and out of PHP mode even in the middle of a PHP block:</p>
    <p><strong>Example #3 Mixing both HTML and PHP modes</strong></p>
    <code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">strpos</span><span style="color: #007700">(</span><span style="color: #0000BB">$_SERVER</span><span style="color: #007700">[</span><span style="color: #DD0000">'HTTP_USER_AGENT'</span><span style="color: #007700">],&nbsp;</span><span style="color: #DD0000">'MSIE'</span><span style="color: #007700">)&nbsp;!==&nbsp;</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">)&nbsp;{<br></span><span style="color: #0000BB">?&gt;<br></span>&lt;h3&gt;strpos()&nbsp;must&nbsp;have&nbsp;returned&nbsp;non-false&lt;/h3&gt;<br>&lt;p&gt;You&nbsp;are&nbsp;using&nbsp;Internet&nbsp;Explorer&lt;/p&gt;<br><span style="color: #0000BB">&lt;?php<br></span><span style="color: #007700">}&nbsp;else&nbsp;{<br></span><span style="color: #0000BB">?&gt;<br></span>&lt;h3&gt;strpos()&nbsp;must&nbsp;have&nbsp;returned&nbsp;false&lt;/h3&gt;<br>&lt;p&gt;You&nbsp;are&nbsp;not&nbsp;using&nbsp;Internet&nbsp;Explorer&lt;/p&gt;<br><span style="color: #0000BB">&lt;?php<br></span><span style="color: #007700">}<br></span><span style="color: #0000BB">?&gt;</span>
</span>
</code>
    <p>A sample output of this script may be:</p>
    <pre>&lt;h3&gt;strpos() must have returned non-false&lt;/h3&gt;
&lt;p&gt;You are using Internet Explorer&lt;/p&gt;
</pre>
    <p>
    Instead of using a PHP echo statement to output something, we jumped out of PHP mode and just sent straight HTML. The important and powerful point to note here is that the logical flow of the script remains intact. Only one of the HTML blocks will end up getting sent to the viewer depending on the result of <a href="http://php.net/manual/en/function.strpos.php" target="_blank">strpos()</a>.  In other words, it depends on
    whether the string <em>MSIE</em> was found or not.
   </p>
  </section>
  <section class="main-section" id="Dealing_with_Forms">
    <header>Dealing with Forms</header>
    <p>
    One of the most powerful features of PHP is the way it handles HTML forms. The basic concept that is important to understand is that any form element will automatically be available to your PHP scripts.  Please read the manual section on
    <a href="http://php.net/manual/en/language.variables.external.php" target="_blank">Variables from external sources</a> for more information and examples on using forms with PHP.  Here is an example HTML form:
   </p>
    <p><strong>Example #1 A simple HTML form</strong></p>
    <pre>&lt;form action="action.php" method="post"&gt;
 &lt;p&gt;Your name: &lt;input type="text" name="name" /&gt;&lt;/p&gt;
 &lt;p&gt;Your age: &lt;input type="text" name="age" /&gt;&lt;/p&gt;
 &lt;p&gt;&lt;input type="submit" /&gt;&lt;/p&gt;
&lt;/form&gt;</pre>
    <p>
    There is nothing special about this form. It is a straight HTML form with no special tags of any kind. When the user fills in this form and hits the submit button, the <var>action.php</var> page is called. In this file you would write something like this:
   </p>
    <p><strong>Example #2 Printing data from our form</strong></p>
    <code><span style="color: #000000">
Hi&nbsp;<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">htmlspecialchars</span><span style="color: #007700">(</span><span style="color: #0000BB">$_POST</span><span style="color: #007700">[</span><span style="color: #DD0000">'name'</span><span style="color: #007700">]);&nbsp;</span><span style="color: #0000BB">?&gt;</span>.<br>You&nbsp;are&nbsp;<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">echo&nbsp;(int)</span><span style="color: #0000BB">$_POST</span><span style="color: #007700">[</span><span style="color: #DD0000">'age'</span><span style="color: #007700">];&nbsp;</span><span style="color: #0000BB">?&gt;</span>&nbsp;years&nbsp;old.</span>
</code>
    <p>A sample output of this script may be:</p>
    <pre>Hi Joe. You are 22 years old.
</pre>
    <p>
    Apart from the <a href="http://php.net/manual/en/function.htmlspecialchars.php" target="_blank">htmlspecialchars()</a> and 
    <em>(int)</em> parts, it should be obvious what this does.  
    <a href="http://php.net/manual/en/function.htmlspecialchars.php" target="_blank">htmlspecialchars()</a> makes sure any characters that are special in html are properly encoded so people can't inject HTML tags or Javascript into your page.  For the age field, since we know it is a number, we can just <a href="http://php.net/manual/en/language.types.type-juggling.php#language.types.typecasting" target="_blank">convert</a> it to an <a href="http://php.net/manual/en/language.types.integer.php" target="_blank">integer</a> which will automatically get rid of any stray characters.  You can also have PHP do this for you automatically by using the <a href="http://php.net/manual/en/ref.filter.php" target="_blank">filter</a> extension. The <var><a href="http://php.net/manual/en/reserved.variables.post.php" target="_blank">$_POST['name']</a></var> and <var><a href="http://php.net/manual/en/reserved.variables.post.php" target="_blank">$_POST['age']</a></var>
    variables are automatically set for you by PHP.  Earlier we
    used the <var><a href="http://php.net/manual/en/reserved.variables.server.php" target="_blank">$_SERVER</a></var> superglobal; above we just 
    introduced the <var><a href="http://php.net/manual/en/reserved.variables.post.php" target="_blank">$_POST</a></var>
    superglobal which contains all POST data.  Notice how the
    <em>method</em> of our form is POST.  If we used the 
    method <em>GET</em> then our form information would live in 
    the <var><a href="http://php.net/manual/en/reserved.variables.get.php" target="_blank">$_GET</a></var> superglobal instead.
    You may also use the <var><a href="http://php.net/manual/en/reserved.variables.request.php" target="_blank">$_REQUEST</a></var> superglobal, if you do not care about the source of your request data. It contains the merged information of GET, POST and COOKIE data.</p>
    <p>
    You can also deal with XForms input in PHP, although you will find yourself comfortable with the well supported HTML forms for quite some time. While working with XForms is not for beginners, you might be interested in them. We also have a <a href="http://php.net/manual/en/features.xforms.php" target="_blank">short introduction to handling data received from XForms</a> in our features section.</p>
  </section>
  <section class="main-section" id="Using_old_code_with_new_versions_of_PHP">
    <header>Using old code with new versions of PHP</header>
    <p>Now that PHP has grown to be a popular scripting language, there are a lot of public repositories and libraries containing code you can reuse. The PHP developers have largely tried to preserve backwards compatibility, so a script written for an older version will run (ideally) without changes in a newer version of PHP. In practice, some changes will usually be needed.</p>
    <p>Two of the most important recent changes that affect old code are:</p>
    <ul>
     <li>
      The old <var>$HTTP_*_VARS</var> arrays are not available as of PHP 5.4.0. The following 
       <a href="http://php.net/manual/en/language.variables.superglobals.php" target="_blank">superglobal arrays</a>
       were introduced in PHP <a href="http://www.php.net/releases/4_1_0.php" target="_blank">4.1.0</a>. 
       They are: <var><a href="http://php.net/manual/en/reserved.variables.get.php" target="_blank">$_GET</a></var>, <var><a href="http://php.net/manual/en/reserved.variables.post.php" target="_blank">$_POST</a></var>, <var><a href="http://php.net/manual/en/reserved.variables.cookies.php" target="_blank">$_COOKIE</a></var>, <var><a href="http://php.net/manual/en/reserved.variables.server.php" target="_blank">$_SERVER</a></var>, <var><a href="http://php.net/manual/en/reserved.variables.files.php" target="_blank">$_FILES</a></var>, <var><a href="http://php.net/manual/en/reserved.variables.environment.php" target="_blank">$_ENV</a></var>, <var><a href="http://php.net/manual/en/reserved.variables.request.php" target="_blank">$_REQUEST</a></var>, and <var><a href="http://php.net/manual/en/reserved.variables.session.php" target="_blank">$_SESSION</a></var>.
     </li>
     <li>
       External variables are no longer registered in the global scope by default.  In other words, as of PHP
       <a href="http://www.php.net/releases/4_2_0.php" target="_blank">4.2.0</a> the PHP directive 
       <a href="http://php.net/manual/en/ini.core.php#ini.register-globals" target="_blank">register_globals</a> is 
       <em>off</em> by default in <var>php.ini</var>. The preferred 
       method of accessing these values is via the superglobal arrays mentioned
       above.  Older scripts, books, and tutorials may rely on this 
       directive being <em>on</em>.  If it were <em>on</em>,
       for example, one could use <var>$id</var> from the URL 
       <em>http://www.example.com/foo.php?id=42</em>.  Whether on 
       or off, <var><a href="http://php.net/manual/en/reserved.variables.get.php" target="_blank">$_GET['id']</a></var> is available.
     </li>
    </ul>
    <p>For more details on these changes, see the section on <a href="http://php.net/manual/en/language.variables.predefined.php" target="_blank">predefined variables</a> and links therein.</p>
  </section>
  
  <section class="main-section" id="What's_next?">
    <header>What's next?</header>
    <p>With your new knowledge you should be able to understand most of the manual and also the various example scripts available in the example archives.</p>
    <p>To view various slide presentations that show more of what PHP can do, see the PHP Conference Material Site: <a href="http://talks.php.net" target="_blank">http://talks.php.net/</a></p>
    <p>Or head on over to <a href="http://php.net/manual/" target="_blank">http://php.net/manual/</a> for more.</p>
  </section>
  
  <section class="main-section" id="Reference">
    <header>Reference</header>
    <ul>
      <li>All the documentation in this page is taken from the <a href="http://php.net/manual/" target="_blank">PHP Manual</a>.</li>
    </ul>
  </section>
</main>

<!--<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>-->
            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Fira+Mono|Questrial');

/* Media Queries can be found at the bottom */

* {
  margin:0;
  padding:0;
}

body {
  font-family: 'Questrial', sans-serif;
}

nav {
  overflow-y: auto;
}

nav header {
  font-size: 2em;
  font-weight: bold;
  text-align: center;
  padding: 0.5em;
  border-bottom: 2px solid #BBB;
}

nav a {
  display: block;
  text-align: center;
  padding: 0.5em;
  font-size: 1.25em;
  text-decoration: none;
  border-bottom: 1px solid #CCC;
  overflow-wrap: break-word;
  word-wrap: break-word;
}
nav a:hover {
  background-color: #BBE;
}

/* "Main" content */

section {
  overflow-wrap: break-word;
  word-wrap: break-word;
}

section header {
  font-size: 2em;
  margin: 1em;
}

section p {
  font-size: 1.25em;
  margin: 1.5em;
}

section a {
  text-decoration: none;
}

code {
  display: block;
  margin: 1.8em;
  padding: 1.5em;
  font-size: 1em;
  font-family: 'Fira Mono', monospace;
  border: 1px dashed #CCC;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

pre {
  display: block;
  margin: 1.8em;
  padding: 1.5em;
  font-size: 1em;
  font-family: 'Fira Mono', monospace;
  border: 1px dashed #CCC;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  word-wrap: break-word;
}

blockquote {
  display: block;
  margin: 1.8em;
  padding: 0.5em;
  font-size: 1em;
  font-family: 'Fira Mono', monospace;
  border: 1px dashed #CCC;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

.example-contents {
  display: block;
  margin: 1.8em;
  padding: 0.5em;
  font-size: 1em;
  font-family: 'Fira Mono', monospace;
  border: 1px dashed #CCC;
  overflow-wrap: break-all;
}

ul {
  margin: 1.8em;
  margin-left: 2.5em;
  font-size: 1.25em;
}

li {
  margin: 1.5em;
}

@media only screen and (min-width: 815px) {
  nav {
    position: fixed;
    top:0;
    left:0;
    width: 330px;
    height: 100%;
  }
  main {
    margin-left: 330px;
  }
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console