MY TASK 3 IS WRONG. NOT WORKING. PLEASE FIX ALSO TASK 3 IS COMING IN BETWEEN OF
ID: 3591465 • Letter: M
Question
MY TASK 3 IS WRONG. NOT WORKING. PLEASE FIX ALSO TASK 3 IS COMING IN BETWEEN OF TASK 2
PHP Arrays, Strings, and File
Lab 4
BY JOHN
Task 1: While loop
Simulate multiple dice rolls until a 6 is reached. Print out the results of each roll.
"); } ?>
Task 2: Array, for-loop, string function
Create an array of strings that is made up of 10 words with the first letter capitalized. Your strings can be of any words you want. Print out these words in a table, where the first column is the word in the array and the second column are the same words in all uppercase. You should use a the rows of the table.
'); foreach($list as $item) { $upper = strtoupper($item); print("$item$upper"); } ?>
Task 3: Files, arrays, and for-loops
This task is to read in the contents of the file classList.txt in to PHP. Then, you should print out each line from the file as a paragraph element. If the line contains the string "EECS", print this out using highlight. See the CSS file for the class name for highlight (you can also view the source of this document to see example of the HTML output).
Explanation / Answer
CODE
<!DOCTYPE html>
<html>
<head>
<title> PHP Arrays, Strings, and File </title>
<meta charset="utf-8">
<link rel="stylesheet" href="Lab4.css" type="text/css">
</head>
<body>
<?php
ini_set('display_errors', 1); # only need to call these functions
error_reporting(E_ALL); # one time
?>
<h1> Lab 4 </h1>
<h1> <span> by john< /span> </h1>
<hr>
<div class="task">
<h2> Task 1: While loop </h2>
<p> Simulate multiple dice rolls until a 6 is reached. Print out the results of each roll. </p>
<div class="output">
<?php
$dice = 5;
while($dice != 6) {
$dice = mt_rand(1, 6);
print("rolled $dice <br /> ");
}
?>
</div>
</div>
<div class="task">
<h2> Task 2: Array, for-loop, string function< /h2>
<p> Create an array of strings that is made up of 10 words with the first letter capitalized.
Your strings can be of any words you want. Print out these words in a table, where the first
column is the word in the array and the second column are the same words in all uppercase. You should use a
the rows of the table. </p>
<div class="output">
<?php
$list = array("One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Deaner");
print('<table>');
foreach($list as $item) {
$upper = strtoupper($item);
print("<tr><th>$item</th><th>$upper</th></tr>");
}
?>
</div>
</div>
<div class="task">
<h2> Task 3: Files, arrays, and for-loops </h2>
<p> This task is to read in the contents of the file< code>classList.txt</code> in to PHP. Then, you should print out each line
from the file as a paragraph element. If the line contains the string "EECS", print this out using highlight.
See the CSS file for the class name for highlight (you can also view the source of this document to see example of the HTML output). </p>
<div class="output">
<?php
/* Task 3: Put your code here */
$filename = 'classList.txt';
$studDetails =array(); // create studDetails of array type to store the students information while reading the file
$myFile = fopen($filename,"r") or die("Unable to open the file!"); // open the file
// loop to read the file line by line
while(!feof($myFile)){
$line = fgets($myFile);
$line = trim($line); // trim the whitespace characters from start and end of line
$studDetails = explode(" ",$line); //breaks the string line into array
// search the array for EECS value
if(in_array("EECS",$studDetails)){
echo '<p> <span class ="highlight">' . $line. '</span></p><br/>' ;
}else{
echo '<p>' . $line . '</p><br/>';
}
}
fclose($myFile); // close the file
?>
</div>
</div>
<body>
</html>
If any queries regarding code please get back to me
Thank you
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.