четверг, 10 декабря 2009 г.

php - echo


For output a text, variables, html tags and etc. is used function PHP echo

PHP echo function will output the text inside it.


Example 1: output variable
<?php
$country = "Canada";
echo $country;
?>
Result:
Canada




Example 2: output text
<?php
echo "Country";
?>
Result:
Country



Example 3: output text with variable
<?php
$my_name = "Valeri";
$my_country = "Georgia";
echo "My name is" . $my_name . " and I am from " . $my_country;
?>
Result:
My name is Valeri and I am from Georgia



Example 4: output text with variables and with html tags
<?php
$my_name = "Valeri";
$my_country = "Georgia";

echo "My name is&nbsp;<b>" . $my_name . "</b><br>&nbsp;&nbsp;&nbsp;and <br>I am from&nbsp;<b>" . $my_country . "</b>";
?>
Result:
My name is Valeri
   and
I am from Georgia

воскресенье, 6 декабря 2009 г.

php - variable


For storing different types of values, we can use variables
  • variables in PHP start with this $ dollar symbol.
  • Name of a variable in php must start with a letter or with this _ symbol.
  • Name of a variable in php must contain only alpha-numeric characters and underscores(abc...z, ABC...Z, 012...9, _)
  • Name of a variable in php should not contain spaces, it will be mistake. if your variable contains more then one word, you can use separator($my_name)
  • A variable does not need to declare value type, Php will automatically converts this variable to the correct data type.
declare text string type variable:
$variable_name = "Myname";

declare text string type variable:
$variable_name = 5;

after decleration a variable, you can use each time you want in your script variables in php
<html>

<body>

<?php

$country = "Canada"
echo $country;

?>

</body>

</html>

The result is :
Canada

echo print the value of the $country variable.

php - comment

you have two way to comment in php

<html>
<body>

<?php
//this is a comment only on the one line

/*
this is a comment block
by this way you can write comment and your script on the one line,
also each line you want
*/

?>

</body>
</html>

php - My first program

<html>
<body>

<?php
echo "Hello World";
?>

</body>
</html>