Question

(10 points) Line sums: Write a PHP funcion called lineSum that accepts a parameter and retums the sum of the integers on that

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code

html file

<html>
<head>
<head>
<body>
<form action="readingFile.php" method="POST">
<table>
<tr>
   <td>Enter File name: </td><td><input type="text" name="filename"></td>
</tr>
<tr>
   <td>Enter line number:</td><td><input type="text" name="lineno"></td>
</tr>
<tr>
   <td colspan="2"><input type="submit" value="Submit"></td>
</tr>
</form>
<body>
</html>

readlingFile.php

<?php
   $fileName=$_POST['filename'];
   $lineNo=$_POST['lineno'];
  
  
   echo "Sum is = ".lineSum($fileName,$lineNo);
  
   function lineSum($fName, $line)
   {
       $file = fopen($fName,"r");
       $count=0;
       $sum=0;
       while(! feof($file))
       {
           $count+=1;
           if($line==$count)
           {
               $numbers = explode(" ", fgets($file));
               foreach ($numbers as &$value) {
                   $sum += (int)$value;
               }
           }
           fgets($file);
       }
       return $sum;
}
?>

ouptus

localhost/jay/readingFile.html Computer Science question Che X X localhost/jay/reading File. htm l Apps C Types Of InformatioUComputer Science question | Che localhost/jay/readingFile.php x X localhost/jay/reading File.php Apps C Types Of Informatio.localhost/jay/reading File.html Computer Science question | Che X C localhost/jay/reading File. htm l Apps C Types Of Informalocalhost/jay/readingFile.php Computer Science question | Che x X localhost/jay/reading File.php Apps C Types Of Informatio..

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
(10 points) Line sums: Write a PHP funcion called lineSum that accepts a parameter and retums the sum of the integers o...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a method called reverseFirstK that accepts an integer k and a queue of integers as...

    Write a method called reverseFirstK that accepts an integer k and a queue of integers as parameters and reverses the order of the first k elements of the queue, leaving the other elements in the same relative order. For example, if a queue named q stores [10, 20 30, 40, 50, 60, 70, 80, 90], the call of reverseFirstK (4, q):should change the queue to store [40, 30 20, 10, 50, 60, 70, 80, 90]. If k is 0 or...

  • C++ Programming 1. Write a function (header and body) that accepts an integer as an argument...

    C++ Programming 1. Write a function (header and body) that accepts an integer as an argument and returns that number squared. 2. Write the code that will fill an integer array named multiples with 10 integers from 5 to 50 that are multiples of five. (This should NOT be in the form of an initialization statement.) 3. Write the code that will display the contents of the integer array named multiples. Recall: the size of the array is 10. 4....

  • 1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector...

    1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector containing the values of the integral (A) for n= 1,2,3,..., n. The function must use the relation (B) and the value of y(1). Your function must preallocate the array that it returns. Use for loop when writing your code. b) Write MATLAB script that uses your function to calculate the values of the integral (A) using the recurrence relation (B), y(n) for n=1,2,... 19...

  • Create a basic math quiz program that creates a set of 10 randomly generated math questions for the following operations:

    Create a basic math quiz program that creates a set of 10 randomly generated math questions for the following operations:AdditionSubtractionMultiplicationDivisionModuloExponentThe following source files are already complete and CANNOT be changed:MathQuiz.java (contains the main() method)OperationType.java (defines an enumeration for valid math operations and related functionality)The following source files are incomplete and need to be coded to meet the indicated requirements:MathQuestionable.javaA Random object called RANDOM has already been declared and assigned, and you must not change this assignment in any way.Declare and assign an interface integer called MAX_SMALL and assign it the...

  • Create a basic math quiz program that creates a set of 10 randomly generated math questions for the following operations:

    Create a basic math quiz program that creates a set of 10 randomly generated math questions for the following operations:AdditionSubtractionMultiplicationDivisionModuloExponentThe following source files are already complete and CANNOT be changed:MathQuiz.java (contains the main() method)OperationType.java (defines an enumeration for valid math operations and related functionality)The following source files are incomplete and need to be coded to meet the indicated requirements:MathQuestionable.javaA Random object called RANDOM has already been declared and assigned, and you must not change this assignment in any way.Declare and assign an interface integer called MAX_SMALL and assign it the...

  • Create a stored procedure named prc_inv_amounts to update the INV_SUBTOTAL, INV_TAX, and INV_TOTAL. The procedure takes the invoice number as a parameter. The INV_SUBTOTAL is the sum of the LINE_TOTAL...

    Create a stored procedure named prc_inv_amounts to update the INV_SUBTOTAL, INV_TAX, and INV_TOTAL. The procedure takes the invoice number as a parameter. The INV_SUBTOTAL is the sum of the LINE_TOTAL amounts for the invoice, the INV_TAX is the product of the INV_SUBTOTAL and the tax rate (8 percent), and the INV_TOTAL is the sum of the INV_SUBTOTAL and the INV_TAX /* Database Systems, Coronel/Morris */ /* Type of SQL : SQL Server */ /* WARNING: */ /* WE HIGHLY RECOMEND...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT