PHP Hello world


PHP Hello world

The following programme is an easy-to-use PHP application that displays "Hello World!."

<?php echo "Hello world"; ?>

output:

Hello world

Escaping to PHP

The PHP parsing engine needs the means to distinguish PHP from other items on the page. It is called 'escaping to PHP' as this is done. This can be done in four ways :

Canonical PHP tags

The PHP tag style is the most universally effective −

<?php...?>

You may rest assured that your tags are always correctly translated when you use this style.

Short-open (SGML-style) tags

This seems like short or short-open tags –

<?...?>

Short tags are the shortest option, as one could imagine. To allow PHP to recognise the tag, you need to do two things.

  • When constructing PHP, select the —enable-short-tags setup option.
  • Set your php.ini file's short open tag setting to on. To parse XML using PHP, this option must be deactivated since the same syntax is utilised for XML tags.

ASP-style tags

The ASP tags imitate the tags used for delineating code sections by Active Server Pages. Such are the ASP-style tags –

<%...%>

You must specify the configuration option in your php.ini file to use the ASP-style tags.

HTML script tags

This looks like HTML script tags –

<script language = "PHP">...</script>

Commenting PHP Code

One comment is that part of a programme which is only available to the human reader and removed before showing the outcome of the programmes. PHP has two commenting formats − Single-line comments − They are generally used for brief explanations or local code notes. Examples of one-line comments are provided below.

<? # This is a comment, and # This is the second line of the comment // This is a comment too. Each style comments only print "An example with single line comments"; ?>