PHP Programming Practice
XAMPP Software
Download and Install
You have to download and install the xampp for windows package software on your desktop or laptop.
What is XAMPP Software?
It is an open-source Web Server Package. XAMPP is more popular for the PHP development environment.
This packaged software complies with the following operating system (OS)-
Unix
XAMPP package software contains-
– Apache Web Server
– PHP
– Filezilla
– MySQL Database
- FTP Service (Helps to Upload and Download files. It is a protocol that works via the internet to send files from the server and receive to the user)
- SMTP Service ( An application that maintains emails between sender and receiver)
- Tomcat Service (Run Java Script and works with windows services)
List of Webserver-
Name | Developer | Open Source | Best Platform |
Apache HTTP Server | Apache Software Foundation | Yes | Unix/Linux |
Internet Information Services (IIS) | Microsoft Foundation | No | Windows |
Jetty | Eclipse Foundation | Yes | All |
Web server tasks-
• To handle
– Get request from the browser
– finds the necessary files
– runs the appropriate scripts
– exchanges cookies if necessary
– returns the results back to the browser
– handling security and encryption
– serving images for other sites (for banners, pictures, etc)
– generating dynamic content
– managing e-commerce functions
Following the xampp control panel, you will see when to click on the xampp icon from the desktop. You can run or stop any services under the xampp package.
Running a PHP program at your laptop-
Put your PHP programs in the xampp\apache\htdocs folder.
Example- c:\xampp\apache\htdocs\salary.php
When want to run PHP program using xampp software,
1. Open Internet Explorer
2. Write at the address bar
3. http:\\localhost
4. http:\\localhost\phpmyadmin
5. http:\\localhost\rashid\salary.php
NB: http:\\localhost means c:\xampp\htdocs
Do the following Practice-
1. Download and Install the xampp package
2. Run and Stop different services using the xampp control panel
3. Make any database and table using Mysql
4. Insert, Update, Delete rows from your table
5. Browse rows from a table.
====================================================================
PHP Programming Basics-
Reference Book-
PHP 5.1 for Beginners
Writer-
Ivan Bayross and Sharanam Shah
PHP is the acronym for "PHP: Hypertext Preprocessor". PHP is a server-side scripting programming language. It is now widely used in the world. Because, it is free, easy to understand, coding and editing. PHP is a very acceptable and popular language for the development of RDBMS based online Application software. PHP is free and can be downloaded and used for application software or website development.
The PHP file extension is ".php". Example- salary.php, lottery.php
PHP supports a wide range of databases like MySQL, Oracle, PostgreSQL, SQLite etc. Any professional can download PHP's latest version install it.
PHP is very compatible with webserver software Apache and IIS. Apache is a free web server and is used in the Linux environment. IIS is the available windows OS. So, IIS is the product of Microsoft Corporation. Both Apache and IIS is very popular in the world and 95% of user use them as webserver.
PHP is the middleware programming script that works between Apache / IIS webserver and Database. PHP is capable to embedded with HTML.
There is a friendship between PHP and c programming. Programming syntax is nearer. If anybody knows c then PHP is easy for him/her. If anybody knows PHP then c is easy to understand for him/her.
Practice 1: PHP installation test
// To test whether PHP installed properly or not
?? View all Global variables
<?php
phpinfo();
?>
Practice 2: Ascii to
char
/*
chr() is used for
ascii to char convert
ord() is used for
char to ascii convert
book page 195
*/
<?php
$tnum=500;
for($i=0;$i<=$tnum;$i++)
{
echo "ASCII Value is :
".$i." Corresponding character value is : ".chr($i)."<br>";
}
?>
// generate a list of
possibilities for two digit numbers consisting of numbers 0 to 5
<?php
echo"<br>";
echo"<br>";
for($i=0;$i<6;$i++)
{
for($j=0;$j<6;$j++)
{
echo$i.$j."
";
}
echo"<br>";
}
?>
// Find Squire and Qube Value
<?php
for ($i=0,$j=0;
$i<9,$j<9; $i++,$j++)
{
echo
"Original valuse : ".$i." Squire valuse :
".$i*$j." Qube
value : ".$i*$i*$i;
echo
"<br>";
}
?>
Practice 5: Generate lottery number using for loop
<?php
$tot_output=255;
for($i=1;$i<=$tot_output;$i++)
{
// put random value
at an array
$tt[$i]=rand(500,999);
}
// Output print
echo " ICB
Recruitment test 2009";
echo
"<br>";
echo " Random
number for Data entry Control Operator Post";
echo
"<br>";
echo "
--------------------------------------------------";
echo
"<br>";
echo
"<br>";
for($k=1;$k<=$tot_output;$k++)
{
echo
$tt[$k]."<br>";
}
?>
// Write a program that will generate grade and gives
statistics on the basis of marks.
<?php
$dist=0;
$frst=0;
$scnd=0;
$thrd=0;
$fail=0;
$marks=array(1,67,82,23,37,57,97,80,9,0,99,45,78,93,28,39,85);
foreach($marks as $mark)
{
if($mark>=80)
{
echo
" The result for $mark marks is : Distinction.<br>";
$dist++;
}
else if
($mark>=60)
{
echo
" The result for $mark marks is : First Class.<br>";
$frst++;
}
else if
($mark>=45)
{
echo
" The result for $mark marks is : Second Class.<br>";
$scnd++;
}
else if
($mark>=33)
{
echo
" The result for $mark marks is : Third Class.<br>";
$thrd++;
}
else
{
echo
" The result for $mark marks is : Fail.<br>";
$fail++;
}
}
echo " <br><br>";
echo "Result statistics <br><br>";
echo "Total Distinction got : $dist<br>";
echo "Total First Class got : $frst<br>";
echo "Total Second Class got : $scnd<br>";
echo "Total Third Class
got : $thrd<br>";
echo "Total Failed : $fail<br>";
?>
Practice 7: Write a PHP program that generates the HASH value of a given text
// sha stands for secured hash algorithm
<?php
// sha stands for secured hash algorithm
echo strtoupper("40 characters output"."<br><br>");
print sha1("Rashid")."<br><br>";
print sha1("mamun")."<br><br>";
print sha1("Mamun")."<br><br>";
print sha1("md. abdur rashid")."<br><be>";
?>
The following output will see on the screen-
40 CHARACTERS OUTPUT
9bdb930b6eccb89f8d95bd9a34b4bc459bed3ff7
f87095637ed82c1e6d131b714674b30174b7e83c
21bad65b5c226e32692f0192ffad4801918c2dc6
5dfc4cc5f56bd0184409c2e4d4354dfe920cb89a
Practice 8: Write a PHP program that generates the HEXA value of a given text
// Give 32 characters hexadecimal output.
// md stands for message digest
// md5() function gives the 128 bit 'fingerprint' or 'message digest' of the given input. This output can be used in digital signature.
<?php
echo strtoupper("32 characters output"."<br><br>");
print md5("Rashid")."<br><br>";
print md5("mamun")."<br><br>";
print md5("Mamun")."<br><br>";
print md5("md. abdur rashid")."<br><br>";
?>
32 CHARACTERS OUTPUT is
12aaedf2544497666587758bba8a3838
c8e36a853fe91f3a4a3c4d739e830139
1b48dad02e2c9dff96a34f08a4eb5e80
387c0f6cc2d39954a09643cb17a6c753
Practice 9: Write a PHP program that sum of a given input
// create a function that make sum
<?php
$var1=295;
function mysum()
{
global $var1,$var2,$total;
$total=$var1+$var2;
return($total);
}
$var2=89;
mysum();
echo "<br>";
echo "<br>";
echo " Total calculated value : ".$total;
echo "<br>";
$grant_total=$total+500;
echo " Total grant value : ".$grant_total;
/*
In php global variables must declare inside the function
*/
Program Output:
Total calculated value: 384
Total grant value: 884
Practice 10: Write a PHP program to find the salary
// create a function that makes your monthly salary
<?php
function salary($basic)
{
$hrent=$basic*0.50;
$medical=900;
$pf=$basic*0.10;
$gi=200;
$car=100;
$ssss=$basic+$hrent+$medical-$pf-$gi-$car;
return($ssss);
}
$bb=0;
$basic=25000;
$total_salary=salary($basic);
echo "<br>";
echo "<br>";
echo "<br>";
echo " Total salary encountered : ".$total_salary;
Program output:
Total salary encountered: 35600
NB: You can put your valuable comments to improve the blog content. The writer is Oracle Certified Professional, trainer, innovator, and researcher and can be contacted at the mail rashid.eee.cse@gmail.com
0propquaePma_yo Sean Shop https://marketplace.visualstudio.com/items?itemName=piedatur-ho.CONSTRUCT-gratuita-2022
ReplyDeletebebulllynin
sponangraphnu Susan Ortega https://wakelet.com/@cosstingnterag808
ReplyDeletebapcompmondse
Usidebulse-1992 Mela Jordan https://wakelet.com/@vahendvercu226
ReplyDeletemontranhedsschul