Thursday, July 29, 2010

PHP Syntax

• PHP syntax is very much similar to language C but the whole code of php is contained within a tag.

• All php codes must be contained within the following:

<?php

?>

Or in shorthand form

<?

?>

But this shorthand tag must be supported by your server and I suggest that standard form should be used i.e. <?php

• As you know that php code is inserted in html code, so if you save your file having html code embedded with php code with extension .php then that becomes your php file. But if you save your file with .html extension then php code will not be interpreted by the server.

• A simple php program having php code embedded in html code:

<html>

<head>

<title>My first php page</title>

</head>

<body>

<?php

echo “Hello World...”;

?>

</body>

</html>



Output:

Hello World...

• After writing this code on a text-editor like notepad, save this file with .php extension(helloworld.php) in www(C:/wamp/www) directory. Now you can run your file on your localhost.

• Let us discuss code:

you all are familiar with html code. New thing is code inside <?php, ?> tags. Echo is a command used for displaying something, you can also use ‘print’ command in place of ‘echo’. What you want to display on screen, write in inverted commas. At the end of each statement there should be a semicolon.

• White space is ignored between php statements.

No comments:

Post a Comment