Some Examples on PHP programs
Use desktop site in Smart phones to visit our post in best manner
Introduction to PHP:
PHP is a Hypertext Preprocessor language. It is interpreted and Server-side Scripting language. It is designed for web development. Program syntax is similar to C and Perl languages. It is executed only in servers. Without servers, we can't executed it. PHP can have text, HTML, CSS, Javascript like this. PHP generates a dynamic contents, collect form data, send & receive cookies. It can easily helps user to interact with database. It is open source language. It is mostly used to write application's logic.
For executing PHP file you need to have a server, a data base and PHP file. PHP, MySQL and Apache are open source. So we can download separately or we can download this all softwares as a package. WAMP and LAMP or the packages of PHP, MySQL, Apache, MariaDB. So, we can download anyone from the net. LAMP only supports for Linux OS. WAMP supports Windows OS. In this generation, Windows is the most preferable OS. If you have Windows as OS, you can download WAMP.
Don't you know how install WAMP server, you can click the link given below, which helps you to how download and install WAMP server in your system.
File Storing
You can create a php file using text-editor like notepad, notepad++ or etc.. After creating php file, save it with the extension of ".php" in the location of,
Local Disk (C): --> wamp64 --> www --> file_name.php
If you failed to add ".php" that file will not be run as php. If you failed to store the file in the specific location "wamp" server cannot access the php file.
1. To check whether a given number is Odd or Even
<html>
<head>
<title>Odd or Even</title>
</head>
<body>
<center>
<form method="get">
<br>
<tr>
<td><b>Enter the number : </b></td>
<td><input type="text" name="number"></td>  
<td ><input type="submit" value="Submit"></td>
</tr>
</form>
<?php
$n=$_GET['number'];
if($n % 2==0)
echo "Given number ".$n." is even";
else
echo "Given number ".$n." is odd";
?>
</center>
</body>
</html>
Output
The "Enter the number : " , textbox, and submit button are created by html. User need to give value in the text box. After giving value he will press submit button or enter to check whether the given number is odd or even. PHP program will get that user's value and check it. Is that odd or even. After checking, according to the user value the output will be printed.
2. To print the numbers according to given Rows & Columns
<html>
<head>
<title>Listing numbers</title>
</head>
<body>
<center>
<form method="post">
<tr>
<td><center><b>Enter the r : </b> <input type="text" name="r"></center></td>
</tr>
<br>
<tr>
<td><center><b>Enter the c : </b><input type="text" name="c"></center></td>
</tr>
<br>
<tr>
<td><center><input type="submit" value="Submit"></center></td>
</tr>
</form>
<?php
$a=$_POST['r'];
$b=$_POST['c'];
$k=1;
echo "<table border=\"5\" style='border-collapse: collapse;'>";
for($i=1;$i<=$a;$i++)
{
echo "<tr>";
for($j=1;$j<=$b;$j++)
{
echo "<td> $k </td>";
$k+=1;
}
echo "<br>";
}
echo "</table>";
?>
</center>
</body>
</html>
Output
User need to give r and c value in textbox. After giving the value the inputs of the user will be sent to the php program. According to the number of row and column, the table will be printed.
3. To print the numbers which divided by the certain number between the given range
<html>
<head>
<title>Divisible number between a and b</title>
</head>
<body>
<center>
<form method="get">
<tr>
<td><b>Enter the number A : </b> <input type="text" name="a"></td>
</tr>
<tr>
<td><b>Enter the number B : </b> <input type="text" name="b"></td>
</tr>
<tr>
<td><b>Enter the number C : </b> <input type="text" name="c"></td>
</tr>
<tr>
<td><input type="submit" value="Submit"></td>
</tr><br>
</form>
<?php
$m=$_GET['a'];
$n=$_GET['b'];
$o=$_GET['c'];
$i=$m;
while($i<=$n)
{
if($i % $o==0)
echo "$i <br>";
$i++;
}
?>
</center>
</body>
</html>
Output
User need to give 3 values. A and B are the starting and ending ranges respectively. Between this range, the numbers which are divided by the C will be printed.
If you have any doubts on this you can comment on the post.
The mentioned above all examples, PHP and HTML are embedded with same document. But, you can also use separate HTML code and PHP code. You can connect those HTML and PHP by <form action=" "> tag. I have given a drive link, from that you can see the examples. From that you can know about how to use action method.
Subscribe Knowsomethings blogspot for more news and coding, the notifications of every post will be updated to you..
super bro#####
ReplyDeleteThanq Mr. Hunter
ReplyDeleteAwesome choice of words. I really like the way you gave this information in a simple way so that it is easy to understand. I hope you will keep posting this kind of post. Know Why Hire A PHP Developer?
ReplyDeleteI really want to share this piece of information with the students of php training course.
ReplyDeleteFor Expert Training & Guaranteed placement in php Apply in Ducat Today
Thanks for Sharing this informations. College Assignment Help is a website that allows you to Online Assignment Help online. Easily to write, Assignment Help Online with trained teachers in Online Classes For Indian Students..
ReplyDeletePHP Course in Noida
ReplyDeleteSAP QM Training In Noida
ReplyDeletePHP Training in Gurgaon
ReplyDeleteThis comment has been removed by the author.
ReplyDelete