PHP Syntax


What is PHP Syntax?

PHP syntax defines the rules and structures needed to create proper PHP code.

 

This section explains how to manage PHP tags and perform actions like declaring variables and writing functions while demonstrating the use of control structures and embedding PHP code into HTML.

 


PHP Tags

PHP code must be contained within these specific tags.

<?php
   // Your PHP code here
?>

 

  • PHP files typically have a .php extension
  • PHP considers any content located outside its tags as HTML code.

Echo and Print Statements

These are used to output text to the browser.

 

echo "Hello, World!";
print "Welcome to PHP!";

notepad

Echo operates with better speed while handling multiple parameters but print returns a value (1).


Example

 <!DOCTYPE html>
<html>
<body>
<?php
    // This is a PHP comment
    echo "Hello, World!";
?>
</body>
</html>



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.