Monday, March 9, 2009

PHP Syntax

PHP Tags


PHP is a web scripting language which means it was desgined to work with HTML. can easily embed PHP code into your HTML code. When writting php code, you enclose your PHP code in special php tags. This tells the browser that we're working with PHP.

<?php
//your php code goes here
?>>


PHP and HTML

<html>
<title>my php page</title>
<body>
<?php
echo "hello there!";
?>
</body>
</html>


Echo is a special statement in php for outputing data to the browser. This statement is more often used when
we need to print something to the browser.

My First PHP Page

  1. Open up notepad.
  2. Copy paste the above PHP and HTML code in notepad.
  3. Now, lets save the file in our www folder, i.e. c:/wamp/www
  4. Name the file my_php_page.php and save it in your www folder.
  5. Now, go to http://localhost/my_php_page.php in your web browser.
Example - Make Text Bold

<?php
echo "<b>hello there!</b>";
?>

Output

hello there

No comments: