Basic Syntaxt
As you know already when we write a java script in a html page we use <script></script> tags. Like that in php we use like this.
<?php
?>
ans also you must save file with extention .php for support php scripts. check with this code
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Test one</title>
</head>
<body>
<?php
print("Hello World !");
?>
</body>
</html>
save the file as test1.php inside the htdocs->Newfolder. The go to the browser and and put the url to the this php file. in my case 'localhost:8081/Newfolder/test1.php'. Note that 'print()' function use for print some to html page.
PHP Variable
In php all variables in PHP are denoted with a leading dollar sign ($). Variables in PHP do not have intrinsic types(a variable does not know in advance whether it will be used to store a number or a string of characters).PHP does a good job of automatically converting types from one to another when necessary.
Php has eight data types (Integer, Double, Boolean, NULL,String, Array, Object, Resources). Lets do a simple example.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Test Two</title>
</head>
<body>
<?php
$num1_int = 100; // integer number
$num2_int = 50; // integer number
$num1_double = 0.5; //double number
$str1 ="Hello"; // String
$your_name = "Harshana"; // String
echo "<h1>".$str1." ".$your_name."</h1>";
echo "<p> num1_int + num2_int = ". ($num1_int+$num2_int)."</p>";
echo "<p> num1_int + num1_double = ". ($num1_int+$num1_double)."</p>";
echo "<p> num1_int - num2_int = ". ($num1_int-$num2_int)."</p>";
echo "<p> num1_int - num1_double = ". ($num1_int-$num1_double)."</p>";
echo "<p> num1_int x num2_int = ". ($num1_int*$num2_int)."</p>";
echo "<p> num1_int x num1_double = ". ($num1_int*$num1_double)."</p>";
echo "<p> num1_int / num2_int = ". ($num1_int/$num2_int)."</p>";
echo "<p> num1_int / num1_double = ". ($num1_int/$num1_double)."</p>";
?>
</body>
</html>
In here "echo" used to print some thing like print() function. I use dot (.) operator for join string. Save the file as test2.php. and run it and check the browser source code for getting more understanding.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.