function parseTweet($s) { return parseTags(parseNames(parseLinks($s))); }
} //gives equal spacing based on total length of spaces minus length of string function spacing($totalCharacters, $stringValue) { $lengthOfString = strlen($stringValue); //turns value of integers into strings $numberOfSpaces = $totalCharacters - $lengthOfString; $stringValueWithSpaces = $stringValue; for ($i = 0; $i < $numberOfSpaces; $i++) { $stringValueWithSpaces .= " "; } return $stringValueWithSpaces; } echo "====================================================================" . PHP_EOL; //grabs text file and renames as a variable $unitsSorted = parseNames('parsecsv.txt'); //count employees function countEmployees($array) { return count($array); } //gets the number of employees to count from line 51- $unitsSorted echos it out to HRO- human readable output $employeeCount = countEmployees($unitsSorted); echo "There are {$employeeCount} total employees working." . PHP_EOL; //adds units sold from all employees together function soldUnits($array) { $sumOfUnitsSold = 0; foreach ($array as $key => $value) { $sumOfUnitsSold = $value['Units_Sold'] + $sumOfUnitsSold; }
<?php $header = ['Units', 'Full Name', 'Employee Number']; $newHeader = implode(" | ", $header); var_dump($newHeader); function parseNames($filename) { $filename = 'report.txt'; $handle = fopen($filename, 'r'); $contents = fread($handle, filesize($filename)); $contentsArray = explode("\n", $contents); for ($i = 0; $i <= 5; $i++) { $headerInfo = array_shift($contentsArray); } foreach ($contentsArray as $employeeParsed) { $employeeArray = explode(", ", $employeeParsed); $employeeNumber = $employeeArray[0]; $unitsSold = $employeeArray[3]; $fullName = $employeeArray[1] . " " . $employeeArray[2]; $employeeInfo[] = ['Units Sold' => $unitsSold, 'Full Name' => $fullName, 'Employee Number' => $employeeNumber]; arsort($employeeInfo); } return $employeeInfo; } var_dump(parseNames('report.txt'));