Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $lines = preg_split('/\n/', $_GET['text']);
- $artist = $_GET['artist'];
- $property = $_GET['property'];
- $order = $_GET['order'];
- $songs = [];
- for ($i = 0; $i < count($lines); $i++) {
- $line = preg_split('/\s*\|\s*/', $lines[$i], -1, PREG_SPLIT_NO_EMPTY);
- $name = trim($line[0]);
- $genre = trim($line[1]);
- $tempArr = preg_split('/\s*,\s*/', $line[2], -1, PREG_SPLIT_NO_EMPTY);
- asort($tempArr);
- $downloads = trim($line[3]);
- $rating = floatval(trim($line[4]));
- if (in_array($artist, $tempArr) && count($line) == 5) {
- $songs[] = ['name' => $name, 'genre' => $genre, 'artists' => $tempArr, 'downloads' => $downloads, 'rating' => $rating];
- }
- }
- if (count($songs) > 0) {
- //get sort keys:
- foreach ($songs as $key => $row) {
- $sortProperty[$key] = $row[$property];
- $sortSongNames[$key] = $row['name'];
- }
- // Sort the data:
- if ($order == 'ascending') {
- array_multisort($sortProperty, SORT_ASC, $sortSongNames, SORT_ASC, $songs );
- } else {
- array_multisort($sortProperty, SORT_DESC, $sortSongNames, SORT_ASC, $songs );
- }
- echo '<table>' . "\n";
- echo '<tr><th>Name</th><th>Genre</th><th>Artists</th><th>Downloads</th><th>Rating</th></tr>' . "\n";
- foreach ($songs as $song => $data) {
- echo '<tr>';
- echo "<td>" . htmlspecialchars($data['name']) ."</td><td>" . htmlspecialchars($data['genre']) .
- "</td><td>" . htmlspecialchars(implode(', ', $data['artists'])) . "</td><td>" .
- htmlspecialchars($data['downloads']) . "</td><td>" . htmlspecialchars($data['rating']) . "</td>";
- echo '</tr>' . "\n";
- }
- echo '</table>';
- } else {
- echo '<table>' . "\n";
- echo '<tr><th>Name</th><th>Genre</th><th>Artists</th><th>Downloads</th><th>Rating</th></tr>' . "\n";
- echo '</table>';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement