PHP

PHP-Syntax Overview

PHP-Syntax Overview

There should be a way so that the PHP parsing engine can differentiate the PHP code from other elements on the page. This mechanism is known as escaping to PHP. It has four ways. 

  • Canonical PHP tags- 

It is the most Universal effective PHP tag as by using this there is the positivity that the tags will be interpreted correctly.

Syntax - <?php……?>

  • Short-open (SGML-style) tags-

As the name suggests it is the shortest option. You can do one of the two things mentioned below to enable PHP to recognize the tags.

  • When you are building PHP choose the –enable –short-tags-configuration option.
  • Set the Short_open_tag setting in the php.ini file to on. To parse the XML with PHP the option must be disabled. As the same syntax is used for XML tags.

             Syntax - <?.......?> 

  • ASP-style tags 

To delineate code blocks the ASP-style tags mimic the tags used by Active Server Pages. To use the tag you need to set the configuration option in your php.ini file.

Syntax - <%.......%>

HTML script tags 

Syntax - <script language= “PHP”>……</script>

Here both the statements are equivalent. 

  • Running PHP Script from Command Prompt- you can run PHP on your command prompt as well.

Let’s consider you have some content in the test.php file