PHP Free Tutorial

Introduction To PHP

In PHP, Programming by Baqir Ali

PHP Tags

PHP commands or codings should be written within PHP tags just like html. So for that we should use PHP tags. There are many types of PHP tags.

  • <?php code ?> is on by default
  • <script language=”php”> code </script> is on by default
  • <? code ?> to use this follow the following steps
    • Go to C:\xampp\php
    • open php.ini in Notepad
    • short_open_tags=off set it On
  • <% code %> to use this follow the following steps
    • Go to C:\xampp\php
    • open php.ini in Notepad
    • asp_tags=off set it On

Print / Echo in PHP

<?php
	print("This is a PHP Statement ");
	print"This is a PHP Statement ";
	echo"This is a PHP Statement ";
?>

Output:

This is a PHP Statement This is a PHP Statement This is a PHP Statement

Remember: White spaces are not considered in PHP. So in order to print newline or spaces in PHP, we will embed HTML code in PHP.

<?php
	print("This is a <b>PHP</b> Statement <br>");
	print"This is a <b>PHP</b> Statement  <br>";
	echo"This is a <b>PHP</b> Statement  <br>";
?>

Output:

This is a PHP Statement
This is a PHP Statement
This is a PHP Statement

Comments in PHP

Comments are used to mark invisible a line of code for compilers. We mark comment on those lines that we don’t want compilers to compile such as the description of code. There are multiple types of comments.

  • // single line comment
  • # single line comment
  • /* */ multi-line comment

Example:

<?php
	print("This is a <b>PHP</b> Statement <br>");
	# <br> is an html tag for new line
	print"This is a <b>PHP</b> Statement  <br>";
	echo"This is a <b>PHP</b> Statement  <br>";
?>

Support us by sharing this post