Hello, PHP Lovers! Today we are going
to make a simple funny project by using SWITCH statement of PHP .
The plan is:
- Take a name input from user which can be user's name.
- Give a word to every letter of taken input!
So PAL, can you do it?
Well, don't worry! I have got a plan
for you!
Let's see the image of what I already
made!
>>>>>>>> Watch LIVE! <<<<<<<<<
First make a HTML form which can take
input and I'll keep it in $ip variable. Then, I'll bring those
into $op into upper case.
Let's go through the codes:
<?php
if(isset($_POST['input'])){
$ip = $_POST['input'];
$op = strtoupper(rtrim( $ip));
echo " Hello, ".
strtoupper($ip)." ! Your Inserted Name Goes For : ";
?>
<?php
$splited =
str_split($op);
$i =0;
for( $i=0; $i < sizeof($splited);
$i++ ){
switch ( $splited[$i] ){
case "A":
echo "A: Affectionate<br/>";
break;
case "B":
echo "B: Brave<br/>";
break;
case "C":
echo "C: Colorful<br/>";
break;
case "D":
echo "D: Decent<br/>";
break;
case "E":
echo "E: Exciting<br/>";
break;
case "F":
echo "F: Fascinate<br/>";
break;
case "G":
echo "G: Gorgeouse<br/>";
break;
case "H":
echo "H: Harmonic<br/>";
break;
case "I":
echo "I: Irritative<br/>";
break;
case "J":
echo "J: Jolly<br/>";
break;
case "K":
echo "K: Kind<br/>";
break;
case "L":
echo "L: Lonely<br/>";
break;
case "M":
echo "M: Mature<br/>";
break;
case "N":
echo "N: Negative<br/>";
break;
case "O":
echo "O: Optimistic<br/>";
break;
case "P":
echo "P: Pathetic<br/>";
break;
case "Q":
echo "Q: Quick<br/>";
break;
case "R":
echo "R: Realist<br/>";
break;
case "S":
echo "S: Sophisticated<br/>";
break;
case "T":
echo "T: Talkative<br/>";
break;
case "U":
echo "U: Unlucky<br/>";
break;
case "V":
echo "V: Vivid<br/>";
break;
case "W":
echo "W: Weak<br/>";
break;
case "X":
echo "X: Xanthippe<br/>";
break;
case "Y":
echo "Y: Youthful<br/>";
break;
case "Z":
echo "Z: Zealous<br/>";
break;
default:
echo "<br/>";
}
}
}
?>
That is how you can make a simple Name
Game by PHP.
No comments:
Post a Comment