PHP Syntax and Tags

PHP script is executed on server, it check for opening and closing tags (<?php ?>), outside of the code from PHP tags ignored by the PHP parser.

PHP Syntax/tags

PHP script starts with "<?php" and end with "?>", PHP parser also allow short open tag <?, it is allow when "short_open_tag" is enabled in PHP.ini file.

 <?php echo "Hello World";?>

PHP file default extension is ".php"

PHP Case Sensitivity

All PHP variable names and constant are case-sensitive.

$lang = "PHP";
echo "My favourite language is " . $lang;
//Output:: My favourite language is PHP

echo "My favourite language is " . $Lang;
//Notice: Undefined variable: Lang

echo "My favourite language is " . $LANG;
//Notice: Undefined variable: LANG

//CONSTANT
define('WEBSITE','qoify.com');
echo Website;
//Notice: Use of undefined constant Website - assumed 'Website'

PHP keywords (if, else, while, echo, print, etc.), classes, methods, functions, language constructs, and user-defined functions are not case-sensitive.

All there statements are same.

$lang = "PHP";
echo $lang; // PHP
ECHO $lang; // PHP
ecHo $lang; // PHP

Escaping from HTML in PHP

PHP parser is ignored outside of PHP opening and closing tags

Example 1 : PHP and HTML Code

<p><h1>HTML Heading</h1></p>
<?php echo "PHP Code"; ?>
<p>HTML code ingnored by PHP Parser</p>

Example 2 : Escaping Using structures with conditions

<?php if($check==1): ?>
This part will show if condition is TRUE
<?php else: ?>
This part will show when condition is FALSE
<?php endif; ?>