Press enter to see results or esc to cancel.

Lesson 3 – Getting started – First Step to php

Share this
Table of Contents
    1. Embed PHP code

To see if PHP is installed on a server, you need a PHP file (eg phpinfo.php ) with the following content:


Lesson 3 - Getting started - First Step to php - Lesson 3 - Getting started - First Step to php - Lesson 3 - Getting started - First Step to php - how to install php script

You can simply insert this code in a text editor, eg Notepad. Then click on Save, and enter the file name phpinfo.php.  Please make sure that Notepad does not save this file as a .txt text file, but actually has the file extension .php . Then you copy the file into the folder htdocs of your xampp installation (eg D:\xampp\htdocs).

Instead of Notepad, you can also use any other editor. For starters, I recommend the free Notepad ++.

If you call this page now ( http://localhost/phpinfo.php ), you will see if PHP is installed on this server or not. If PHP is installed, several tables are displayed listing what is installed and what is not, including which version of PHP is installed on the server (top of the page). If no PHP is installed, either nothing will be displayed or an error message will be displayed, maybe the file will also be offered for download. How to install PHP was in the first part of the tutorial: Installing PHP.

Embed PHP code

A PHP file can contain both HTML commands and PHP commands. The HTML commands you write as usual in the .php file, as you know it from HTML files.

If you want to include PHP commands in the file, you must first start a scripting environment. This is done by <? Php. Then comes your PHP code. This script environment is terminated by means of ?>.

<! DOCTYPE html>
<meta charset = "UTF-8" />
<title> Your first PHP script </ title>
</ Head>
<h1> Welcome </ h1>

<p> This is your first php file. You can start a scripting environment as follows:
<? Php
echo "Data can be output via echo";
?> </ P>

<p> Later you can create dynamic content in PHP. A simple example is to print the current date:
<? Php
echo date ("d.m.Y H: i: s");
?> </ P>
</ Body>
</ Html>

In the script above, you have a standard HTML5 framework. Between the HTML commands, there are always PHP sections. The first section outputs only one text. The second section displays the current date and time.

When a user calls this file through your web server (eg http://localhost/first.php), the PHP interpreter becomes active and evaluates all PHP scripting environments. The result of the PHP code is then inserted into the page. The visitor does not have access to the actual PHP code.

How useful was this Lesson?

Click on a star to rate it!

Average rating / 5. Vote count:

Be the first to rate this post.!

As you found this post useful...

Follow us on social media!

We are sorry that this lesson was not useful for you!

Let us improve this lesson!

Tell us how we can improve this lesson?

Share this