PHP Syntax

PHP syntax and semantics are similar to most other programming languages (C, Java, Perl) with the addition that all PHP code is contained with a tag, of sorts. All PHP code must be contained within the following…

PHP Code:

<?php
Some coding here......
?>

or the shorthand PHP tag. i.e

<?
Some php coding here
?>

Note: If you are writing PHP scripts and plan on distributing them, we suggest that you use the standard php syntax (which includes the <?php) rather than the shorthand php syntax. This will ensure that your scripts will work, even when running on other servers with different settings.

How to save your php pages

If you have PHP inserted into your HTML and want the web browser to interpret it correctly, then you must save the file with a .php extension, instead of the standard .html extension. So be sure to check that you are saving your files correctly. Instead of index.html, it should be index.php if there is PHP code in the file.

Example html & php page

Below is an example of one of the easiest PHP and HTML page that you can create and still follow web standards.

<html>
<head>
<title>My first PHP page-techTutorialsOnline.com</title>
</head>
<body>
<?php   
echo "<h1>Hello!</h1>";
echo "<h2>This is my first code in php.</h2>";
?>
</body>
</html>
This is how to use PHP Syntax.

If you have any question, ask it at our Forum Section.