Php Syntax or code are the php script text, which execute on the php compiler/server and after execution it returns the output in HTML text and send back to the browser and this HTML output can be visible in the any browser. Php syntax have statement, variables and methods like other programming languages.
PHP File Extension
To save the php document '.php' extension required. you can name your document and in end of the file user the '.php' extension using this extension the server will identify and execute the php file. here some examples for file naming:-
loginForm.php
registration_form.php
forgot-password.php
template1.php
MyClass.php
PHP block
PHP block is the collection of the angle braces, question marks and php text written in specific arrangement
<?php ?>.
- To place the php script in the document we need to user the php block <?php ?>.
- PHP blocks can be written anywhere in the document.
- PHP use these php block because it easy to embed within HTML text and easy to identify by the server/compiler where exact php code in the document.
- One necessary thing to understand we can also write the pure HTML code in the php document. file will execute on server.
- Php code embed within the HTML text the design part of the php web page all are HTML and the server execution output is also HTML so finally a full HTML showed by browser.
- So browser only hold the html not the php just browser show the server return html.
<!DOCUMENT html>
<html>
<body>
<h1>My First PHP document</h1>
<?php echo "String Print"; ?>
</body
</html>
PHP Comments
A comment is instructions or can be note about the program which can be written within the php block. Comments are not execute on the server/compiler. Sometime php scripts are also commented as references but not execute on execution time. Comments are a powerful reminder source of the instructions, notes and references.
Here two types of the comments in the php first is single line and second is the multi-lines. It easy to understand that single line comments are used to comment the text in the single line in case you want to comments the multi-lines you can use the multi line comment.
<?php
// THIS IS A SINGLE LINE COMMENT
/*
THIS IS A MULTI-LINES COMMENT
USE TO COMMENT THE MULTIPLE LINES
THESE TEXT NOW NOT EXECUTE ON SERVER
*/
// ALSO CAN COMMENT THE PHP SYNTAX
// echo "PRINT STATEMENT";
?>
PHP Case Sensitivity
In some of the cases php is case sensitive but here some of the things e.g. echo, if, else, while etc. and user defined functions are not case sensitive.
<!DOCUMENT html>
<html>
<body>
<?php
ECHO "Print String!<br>";
echo "Print String!<br>";
EcHo "Print String!<br>";
?>
</body
</html>
Conclusion
- PHP block is <?php ?>
- PHP statements end with the semicolon (;).
- PHP block written in the PHP block.
- PHP document should be save in the .php file extension.
- PHP Block embed within the HTML.
- PHP document can have only HTML tags.
- PHP document can have only php script.
- PHP document can have both HTML tags and PHP scripts.
- PHP document execute only on the server.
- PHP after execution on server return HTML.
- PHP scripts execute one by one line on the server.
- PHP is server side web development language.
- PHP can be use as OOPS or without OOPS.
- PHP can be use as MVC or any other architecture.
- PHP support multi-line ( /* comments */ ) and single line comments ( // Comments )
- PHP Case Sensitive in some cases.