Wednesday, August 15, 2012

Starring php Basics



  • // single-line comments can be like this
  • # or even like this
  • /* multi-line comments can be like this */
  •  ; The semicolon at the end of the statement is important! 
  • the PHP command echo is a means of outputting text to the web browser

Comparison chart


Echo (PHP)Print (PHP)
Parameters:echo can take more than one parameter when used without parentheses. The syntax is echo expression [, expression[, expression] ... ]. Note that echo ($arg1,$arg2) is invalid.print only takes one parameter.
Return value:echo does not return any valueprint always returns 1 (integer)
Syntax:void echo ( string $arg1 [, string $... ] )int print ( string $arg )
What is it?:In PHP, echo is not a function but a language construct.In PHP, print is not a really function but a language construct. However, it behaves like a function in that it returns a value.

The print() function is slightly slower than echo().

Example:

<html>
<head>
<title>Hello World! PHP</title>
</head>
<body>

<h1>Examples</h1>
<?php echo "Hello World!"; ?>
<br />



<?php
// print works like echo
print "Hello World!";
?>
<br />

<?php
// concatenation
echo "Hello" . " World!<br />";

// simple math
echo 2 + 3;

?>
<br />
</body>
</html>

No comments:

Post a Comment