• We just launched and are currently in beta. Join us as we build and grow the community.

Simple Love Calculator

Govind753159

Security Operation Center Analyst
G Rep
0
0
0
Rep
0
G Vouches
0
0
0
Vouches
0
Posts
125
Likes
168
Bits
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.

  1. <?php
  2. $lcname

    =

    strtolower

    (

    preg_replace

    (

    "/ /"

    ,

    ""

    ,

    strip_tags

    (

    trim

    (

    $_POST

    [

    'per1'

    ]

    .

    $_POST

    [

    'per2'

    ]

    )

    )

    )

    )

    ;
  3. $alp

    =

    count_chars

    (

    $lcname

    )

    ;

  4. for

    (

    $i

    =

    97

    ;

    $i

    <=

    122

    ;

    $i

    ++

    )
  5. {
  6. if

    (

    $alp

    [

    $i

    ]

    !=

    false

    )
  7. {
  8. $answer

    =

    strlen

    (

    $alp

    [

    $i

    ]

    )

    ;

  9. if

    (

    $answer

    <

    2

    )
  10. {
  11. $calc

    [

    ]

    =

    $alp

    [

    $i

    ]

    ;
  12. }
  13. else
  14. {
  15. for

    (

    $a

    =

    0

    ;

    $a

    <

    $answer

    ;

    $a

    ++

    )
  16. {
  17. $calc

    [

    ]

    =

    substr

    (

    $alp

    [

    $i

    ]

    ,

    $a

    ,

    1

    )

    ;
  18. }
  19. }
  20. }
  21. }

  22. while

    (

    (

    $letter

    =

    count

    (

    $calc

    )

    )

    >

    2

    )
  23. {
  24. $lettermitte

    =

    ceil

    (

    $letter

    /

    2

    )

    ;
  25. for

    (

    $i

    =

    0

    ;

    $i

    <

    $lettermitte

    ;

    $i

    ++

    )
  26. {
  27. $sum

    =

    array_shift

    (

    $calc

    )

    +

    array_shift

    (

    $calc

    )

    ;
  28. $answer

    =

    strlen

    (

    $sum

    )

    ;

  29. if

    (

    $answer

    <

    2

    )
  30. {
  31. $addcalc

    [

    ]

    =

    $sum

    ;
  32. }
  33. else
  34. {
  35. for

    (

    $a

    =

    0

    ;

    $a

    <

    $answer

    ;

    $a

    ++

    )
  36. {
  37. $addcalc

    [

    ]

    =

    substr

    (

    $sum

    ,

    $a

    ,

    1

    )

    ;
  38. }
  39. }
  40. }
  41. $answers

    =

    count

    (

    $addcalc

    )

    ;
  42. for

    (

    $b

    =

    0

    ;

    $b

    <

    $answers

    ;

    $b

    ++

    )
  43. {
  44. $calc

    [

    ]

    =

    $addcalc

    [

    $b

    ]

    ;
  45. }
  46. array_splice

    (

    $addcalc

    ,

    0

    )

    ;
  47. }
  48. echo

    $calc

    [

    0

    ]

    .

    $calc

    [

    1

    ]

    ;
  49. ?>

lc1.png

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

  1. <!

    DOCTYPE html>
  2. <

    html>
  3. <

    head>
  4. <

    title>

    Simple Love Calculator</

    title>
  5. <

    link

    rel=

    "stylesheet"

    type=

    "text/css"

    media=

    "screen"

    href=

    "css/style.css"

    />
  6. <

    link

    rel=

    "stylesheet"

    href=

    "bootstrap/css/bootstrap.min.css"

    />
  7. </

    head>
  8. <

    body>
  9. <script language

    =

    "javascript"

    type =

    "text/javascript"

    >
  10. var

    request =

    false

    ;
  11. try
  12. {
  13. request =

    new

    XMLHttpRequest(

    )

    ;
  14. }
  15. catch (

    trymicrosoft)
  16. {
  17. try
  18. {
  19. request =

    new

    ActiveXObject(

    "Msxml2.XMLHTTP"

    )

    ;
  20. }
  21. catch (

    othermicrosoft)
  22. {
  23. try
  24. {
  25. request =

    new

    ActiveXObject(

    "Microsoft.XMLHTTP"

    )

    ;
  26. }
  27. catch (

    failed)
  28. {
  29. request =

    false

    ;
  30. }
  31. }
  32. }
  33. if

    (

    !

    request)
  34. alert(

    "Error initializing XMLHttpRequest!"

    )

    ;
  35. function

    updateDiv(

    person1,

    person2)
  36. {
  37. var

    url =

    "calculate.php"

    ;
  38. var

    params =

    "per1="

    +

    person1 +

    "&per2="

    +

    person2;
  39. request.

    open(

    "POST"

    ,

    url,

    true

    )

    ;
  40. request.

    setRequestHeader(

    "Content-type"

    ,

    "application/x-www-form-urlencoded"

    )

    ;
  41. request.

    setRequestHeader(

    "Content-length"

    ,

    params.

    length)

    ;
  42. request.

    setRequestHeader(

    "Connection"

    ,

    "close"

    )

    ;
  43. request.

    onreadystatechange =

    function

    (

    )
  44. {
  45. if

    (

    request.

    readyState ==

    4

    &&

    request.

    status ==

    200

    )
  46. {
  47. var

    response =

    request.

    responseText;
  48. document.

    getElementById(

    'targetDiv'

    )

    .

    innerHTML =

    response +

    "% "

    ;
  49. }
  50. }
  51. request.

    send(

    params)

    ;

  52. }
  53. </script>
  54. <

    div id =

    "main"

    align =

    "center"

    >
  55. <

    form name =

    "test"

    action =

    "#"

    class

    =

    "form"

    >
  56. <

    h1><

    b>

    Love Calculator</

    b></

    h1><

    hr/>
  57. <

    table border =

    "0"

    >
  58. <

    tbody>
  59. <

    tr>
  60. <

    td><

    span class

    =

    "style1"

    ><

    img src=

    "./img/male.png"

    width=

    "50"

    height=

    "50"

    style=

    "margin-top: 15px;"

    /></

    span>
  61. <

    input size =

    "30"

    class

    =

    "form-control"

    name =

    "per1"

    placeholder =

    "Enter Full Name"

    type=

    "text"

    /><

    br/>
  62. <

    span class

    =

    "style1"

    ><

    img src=

    "./img/female.png"

    width=

    "50"

    height=

    "50"

    /></

    span>
  63. <

    input size =

    "30"

    class

    =

    "form-control"

    name =

    "per2"

    placeholder =

    "Enter Full Name"

    type=

    "text"

    />
  64. </

    td>
  65. <

    td style =

    "background-image: url('img/heart_hands.gif');background-repeat:no-repeat; width: 220px; height: 128px;"

    >
  66. <

    div id =

    "targetDiv"

    valign=

    "middle"

    align =

    "center"

    >

    0

    %</

    div>
  67. </

    td>
  68. </

    tr>
  69. </

    tbody>
  70. </

    table><

    br/>
  71. <

    input onclick =

    "updateDiv(per1.value, per2.value)"

    value =

    "Calculate"

    class

    =

    "btn btn-default"

    type =

    "button"

    >
  72. </

    form><

    br/>
  73. </

    div>
  74. </

    body>
  75. </

    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.
 

452,292

324,736

324,744

Top