Introduction to PHP - Syntax

  »   PHP Introduction  »   Introduction to PHP - Syntax

So let's start creating our first PHP file. The extension for PHP files is .php. You can create a .txt file and just rename it to extension to index.php for example. The name index.php is typically rendered automatically by accessing you domain name.

echo "<h1>My first PHP page!</h1>"; 

This will give you:

my first PHP page

Things to remember about PHP

Now let's stop for a moment and take a look at our code. We can see that it starts with "<?php" and ends with "?>" and we are using echo to output some HTML content. We used quotation marks to wrap the content and we end the line with a semicolon.

There are also some other things to remember:

  • White spaces, tablations and line jumps are ignored in PHP.
  • Although functions names like ECHO, IF, ELSE, WHILE, etc, are all case insensitive. we can not say the same about variable names. For example $MyVar is not the same as $myVar and both are different from $myvar.
  • We can use "//" to create single line comments or "/*" and "*/" for multiple line comments

// this is a simple variable in PHP
$myVar = "myVar has been set";

echo "<p>This PHP output uses lowercase echo</p>"; 
ECHO "<p>Here we are using uppercase ECHO</p>"; 
Echo "<p>And here we are using Capitalized Echo</p>";

echo $myVar;

Case sensitive example.

PHP text editors

While you don't need any special editor to create PHP files there are some that are better than others. And since this depends on everybody's tastes and programming background, you can choose one from the list above

  • Notepad++ - It's the most basic editor for various programming languages including PHP. You can download Notepadd++ here:
  • NetBeans IDE - Is a free open-source Integrated Development Environment (IDE) for software developers. Pretty cool if you ask me. You can check it out here:
  • Sublime Text - Sublime text editor is one of my favorite. It is quite cool for novice and advanced users. You can use it out of the box and you have tons of options to customize. It is suppose to came as you don't have to buy it if you don't want. Go ahead and download it if you like:

Of course there are tones of editors that you can use. Please feel free to leave me a comment and let me know which one is your favorite. You can also find a good list of some other PHP editors on Wikipedia website located here: