Get DevWP - WordPress Development Theme

PHP Syntax

PHP is a server side scripting language written in the C Programming Language and has a similar syntax as C. The purpose of PHP is to keep your processing code on the server which then generates the requested HTML to the person visiting your website.

Creating your First PHP File

You can create a PHP file just as you would create an HTML file. You would use your favorite text editor and make sure you use the file extension .php which is how your web server will know to process the file as PHP.

Basic PHP Syntax

A PHP file can be a stand alone file with functions or classes which we’ll cover in another tutorial and PHP can also be embedded in your HTML. Just make sure to always use the .php file extension even if the majority of code in your document is HTML.


<!DOCTYPE html>
<html lang="en">
<body>

<h1>PHP Syntax Example</h1>

<?php
echo "PHP Powers almost 80% of the Modern Web.";
?>

</body>
</html> 

In the code example above, you will notice we have our general HTML and embedded in the HTML is the opening <?php tag followed by echo with a string nested inside of quotation marks. The string is closed off with a semicolon and finally we have the closing part of the the PHP tag ?> and then back to HTML.

Is PHP Case Sensitive?

Case sensitivity is something you want to watch out for in most programming languages. While some parts of a language might be case sensitive, others might not. Even if something isn’t case sensitive, you should still be consistent.

PHP Variables are Case Sensitive. PHP Keywords like [ if, else, while, echo, function and others ] aren’t case sensitive. As we progress throughout the various tutorials, I will highlight if something is case sensitive or not.

Key Things to Remember

  • You need to use the .php file extension
  • You need to open your PHP Script with the <?php tag
  • Your code will then be nested inside your code block
  • Semicolons are important to use after each Statement
  • PHP has some cases sensitivity. Example: Variables.
  • In most cases, you will need to close off your code block with ?>

That’s the very basics of PHP Syntax.



View Our Themes