year 2015 Group B 11. Write a program in PHP to add three numbers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
<body> <form action="" method="post"> <label>First Number</label> <input type="number" name="first_num" /> <br /> <label>Second Number</label> <input type="number" name="second_num" /> <br /> <label>Third Number</label> <input type="number" name="third_num" /> <input type="submit" name="" value="Submit" /> </form> </body> <?php if($_POST){ $first_num = $_POST['first_num']; $second_num = $_POST['second_num']; $third_num = $_POST['third_num']; $sum = $first_num + $second_num + $third_num; echo 'Sum: '.$sum; } ?> |
12. Write a PHP program to display first and last character of a string.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
<body> <form action="" method="post"> <label>Enter a string</label> <input type="text" name="text" /> <input type="submit" name="" value="submit" /> </form> </body> <?php if($_POST){ $string = trim($_POST['text']); $length = strlen($string); for($i = ($length - 1); $i >= 0; $i--){ if($i == ($length-1)){ echo 'Last character is: '.$string[$i]; } if($i == 0){ echo '<br />First character is: '.$string[$i]; } } } ?> |
13. Create two integer array of size 5 each with data item in them. Then display sum of all the number of both […]
Continue Reading