Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 74,759 times

Contents

Related Categories

An Introduction to PHP - Getting Started

gez

Getting Started

PHP scripts have the extension .php. The PHP script is placed between the <?php and ?> delimiters. The script that is placed between these delimiters is interpreted on the server into HMTL, before being sent to the client. The client will receive a pure HTML page.

Comments

You can comment your code using C++ type comments. The following shows the syntax for inline comments (a comment on a single line), and block comments (comments placed over several lines).

// This is an inline comment
/*
This is a block comment
placed over two or more
lines
*/

Output

There are two basic statements to output text with PHP, either using echo, or print.

Output Using echo

The text to be outputed follows the echo statement.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <title>Starting PHP</title>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<p>
  <?php echo "Hello World<br>"; ?>
</p>
</body>
</html>

Output using print

The text to be outputed follows the print statement.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <title>Starting PHP</title>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<p>
  <?php print "Hello World<br>"; ?>
</p>
</body>
</html>

PHP also offers a shothand way of outputting information, using the <?= and ?> delimiters. The following example prints the variable $name (passed from a form) to greet a user.

Hello <?=$name?>

PHP Information

The phpinfo function is useful for trouble shooting, providing the version of PHP, and how it is configured.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <title>PHP Information</title>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<p>
  <?php phpinfo();?>
</p>
</body>
</html>

I'm available for contract work. Please visit Juicify for details.

Comments

  • Re: [3703] An Introduction to PHP

    Posted by radha_telanakula on 02 Jan 2007

    Here they show how to send valued in one file to another(both are in same folder)
    but i need to send values in one folder to another

  • Re: [3703] An Introduction to PHP

    Posted by pjlewis on 04 Apr 2006

    Yes, I think you're correct, although you could easily have a line like this:

    $num = $_POST['num'];


    to get around that problem. Which I think is what's missing from this tutor...

  • Re: [3703] An Introduction to PHP

    Posted by keepbalance on 04 Apr 2006

    In the PHP file should it be "$_POST["num"]" ?


    instead of just $num?

  • file download

    Posted by narayan on 21 Feb 2004

    hello

    I have in php a header which brings a save as box , but when file is down loaded it contains the 6 blank spaces at the start of of document .
    I have to avoid storing these blank spaces.Plea...

  • String concatenation

    Posted by jeen on 28 Jan 2004

    You can also do string concatenation like
    [code]
    $h = "Hello";
    $w = "World";

    $message = "$h $w";

    [/code]