Basic PHP Syntax

Programming

PHP Syntax

PHP syntax starts with Canonical PHP Tags PHP code place between this. A PHP script can be placed anywhere in the document. On the server, a PHP script is run, and the output of plain HTML is sent back to the browser. The PHP script embedded in HTML pages. We can also use PHP tags inline as we use inline CSS anywhere in the HTML page. PHP files are plain text files save using .php extension. Every PHP command ends with a semi-colon ; same as a programming language.

Case Sensitive in PHP syntax

In PHP, names of variables are case sensitive but names of functions are not case sensitive. If you have specified variable in lowercase, you must use it anywhere in the program in lowercase. If we describe the $str= "webgator"; variable then we must use $str. $STR won’t work anyway. However, the keywords, function, and class names are case-insensitive. If you describe the name of the function in lowercase but call it in uppercase, it will work. For example, if we define the function TEST() {} then calling test() will work too.

PHP Syntax

Short-open tags or SGML-style

As one would expect, short tags are the shortest choice you need to do one of two things to allow PHP to recognize the tags.

When you’re building PHP, select the –enable-short-tags configuration option.

In your php.ini file, set the short_open_tag setting to on. To parse XML with PHP, this option must be disabled, as the same syntax is used for XML tags.

whitespace insensitivity

Whitespace is the items you type that are usually invisible on the keyboard, including spaces, lines, and returns of carriage (end-of-line characters). PHP disrespectful white space means it almost never matters how many white space characters you have in a white space character in a row.one is the same as all of the other characters.