Govind753159
Security Operation Center Analyst
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
300 XP
If your looking for a Simple Web Application for entertainment I have here a Simple Love Calculator using PHP and Javascript. This application has a two inputs of a name for the male and female. Every letter or name that the user encode the application will automatically calculate the percentage of love with that two names that the user encode. The calculation of the percentage is driven by the javascript to show how much percentage that the two name will be each other or not. See the example code below.
⚙ Live Demo
Sample Code
Calculator.php - this code is for the calculation of love and convert to percentage.
Index.php - This is for the HTML form and for the rest of javascript code to catch or fetch the data through the calculation.php
⚙ Live Demo
Hope that you learn in my tutorial. Don't forget to LIKE & SHARE this website. Enjoy Coding.
Download
⚙ Live Demo
Sample Code
Calculator.php - this code is for the calculation of love and convert to percentage.
- <?php
- $lcname
=
strtolower
(
preg_replace
(
"/ /"
,
""
,
strip_tags
(
trim
(
$_POST
[
'per1'
]
.
$_POST
[
'per2'
]
)
)
)
)
;
- $alp
=
count_chars
(
$lcname
)
;
- for
(
$i
=
97
;
$i
<=
122
;
$i
++
)
- {
- if
(
$alp
[
$i
]
!=
false
)
- {
- $answer
=
strlen
(
$alp
[
$i
]
)
;
- if
(
$answer
<
2
)
- {
- $calc
[
]
=
$alp
[
$i
]
;
- }
- else
- {
- for
(
$a
=
0
;
$a
<
$answer
;
$a
++
)
- {
- $calc
[
]
=
substr
(
$alp
[
$i
]
,
$a
,
1
)
;
- }
- }
- }
- }
- while
(
(
$letter
=
count
(
$calc
)
)
>
2
)
- {
- $lettermitte
=
ceil
(
$letter
/
2
)
;
- for
(
$i
=
0
;
$i
<
$lettermitte
;
$i
++
)
- {
- $sum
=
array_shift
(
$calc
)
+
array_shift
(
$calc
)
;
- $answer
=
strlen
(
$sum
)
;
- if
(
$answer
<
2
)
- {
- $addcalc
[
]
=
$sum
;
- }
- else
- {
- for
(
$a
=
0
;
$a
<
$answer
;
$a
++
)
- {
- $addcalc
[
]
=
substr
(
$sum
,
$a
,
1
)
;
- }
- }
- }
- $answers
=
count
(
$addcalc
)
;
- for
(
$b
=
0
;
$b
<
$answers
;
$b
++
)
- {
- $calc
[
]
=
$addcalc
[
$b
]
;
- }
- array_splice
(
$addcalc
,
0
)
;
- }
- echo
$calc
[
0
]
.
$calc
[
1
]
;
- ?>

Index.php - This is for the HTML form and for the rest of javascript code to catch or fetch the data through the calculation.php
- <!
DOCTYPE html>
- <
html>
- <
head>
- <
title>
Simple Love Calculator</
title>
- <
link
rel=
"stylesheet"
type=
"text/css"
media=
"screen"
href=
"css/style.css"
/>
- <
link
rel=
"stylesheet"
href=
"bootstrap/css/bootstrap.min.css"
/>
- </
head>
- <
body>
- <script language
=
"javascript"
type =
"text/javascript"
>
- var
request =
false
;
- try
- {
- request =
new
XMLHttpRequest(
)
;
- }
- catch (
trymicrosoft)
- {
- try
- {
- request =
new
ActiveXObject(
"Msxml2.XMLHTTP"
)
;
- }
- catch (
othermicrosoft)
- {
- try
- {
- request =
new
ActiveXObject(
"Microsoft.XMLHTTP"
)
;
- }
- catch (
failed)
- {
- request =
false
;
- }
- }
- }
- if
(
!
request)
- alert(
"Error initializing XMLHttpRequest!"
)
;
- function
updateDiv(
person1,
person2)
- {
- var
url =
"calculate.php"
;
- var
params =
"per1="
+
person1 +
"&per2="
+
person2;
- request.
open(
"POST"
,
url,
true
)
;
- request.
setRequestHeader(
"Content-type"
,
"application/x-www-form-urlencoded"
)
;
- request.
setRequestHeader(
"Content-length"
,
params.
length)
;
- request.
setRequestHeader(
"Connection"
,
"close"
)
;
- request.
onreadystatechange =
function
(
)
- {
- if
(
request.
readyState ==
4
&&
request.
status ==
200
)
- {
- var
response =
request.
responseText;
- document.
getElementById(
'targetDiv'
)
.
innerHTML =
response +
"% "
;
- }
- }
- request.
send(
params)
;
- }
- </script>
- <
div id =
"main"
align =
"center"
>
- <
form name =
"test"
action =
"#"
class
=
"form"
>
- <
h1><
b>
Love Calculator</
b></
h1><
hr/>
- <
table border =
"0"
>
- <
tbody>
- <
tr>
- <
td><
span class
=
"style1"
><
img src=
"./img/male.png"
width=
"50"
height=
"50"
style=
"margin-top: 15px;"
/></
span>
- <
input size =
"30"
class
=
"form-control"
name =
"per1"
placeholder =
"Enter Full Name"
type=
"text"
/><
br/>
- <
span class
=
"style1"
><
img src=
"./img/female.png"
width=
"50"
height=
"50"
/></
span>
- <
input size =
"30"
class
=
"form-control"
name =
"per2"
placeholder =
"Enter Full Name"
type=
"text"
/>
- </
td>
- <
td style =
"background-image: url('img/heart_hands.gif');background-repeat:no-repeat; width: 220px; height: 128px;"
>
- <
div id =
"targetDiv"
valign=
"middle"
align =
"center"
>
0
%</
div>
- </
td>
- </
tr>
- </
tbody>
- </
table><
br/>
- <
input onclick =
"updateDiv(per1.value, per2.value)"
value =
"Calculate"
class
=
"btn btn-default"
type =
"button"
>
- </
form><
br/>
- </
div>
- </
body>
- </
html>
⚙ Live Demo
Hope that you learn in my tutorial. Don't forget to LIKE & SHARE this website. Enjoy Coding.
Download
You must upgrade your account or reply in the thread to view the hidden content.