Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $artist = $_GET['artist'];
- $sortProperty = $_GET['property'];
- $order = $_GET['order'];
- $inputSongs = explode("\n", $_GET['text']);
- $songsList = array();
- foreach ($inputSongs as $inputRow) {
- $inputRow = preg_split('/\s*\|\s*/', $inputRow, -1, PREG_SPLIT_NO_EMPTY);
- $artists = preg_split('/,\s*/', $inputRow[2], -1, PREG_SPLIT_NO_EMPTY);
- if (!in_array($artist, $artists)) {
- continue;
- }
- sort($artists);
- $song = new stdClass();
- $song->name = $inputRow[0];
- $song->genre = $inputRow[1];
- $song->artists = implode(', ', $artists);
- $song->downloads = (int)$inputRow[3];
- $song->rating = (float)$inputRow[4];
- $songsList[] = $song;
- }
- usort($songsList, function ($a, $b) use ($sortProperty, $order) {
- if ($a->$sortProperty == $b->$sortProperty) {
- return strcmp($a->name, $b->name);
- } elseif ($order == 'ascending') {
- return ($a->$sortProperty > $b->$sortProperty) ? 1 : -1;
- } else {
- return ($a->$sortProperty < $b->$sortProperty) ? 1 : -1;
- }
- });
- echo "<table>\n<tr><th>Name</th><th>Genre</th><th>Artists</th><th>Downloads</th><th>Rating</th></tr>\n";
- foreach ($songsList as $song) {
- $name = htmlspecialchars($song->name);
- $genre = htmlspecialchars($song->genre);
- $artists = htmlspecialchars($song->artists);
- $downloads = htmlspecialchars($song->downloads);
- $rating = htmlspecialchars($song->rating);
- echo "<tr><td>{$name}</td><td>{$genre}</td><td>{$artists}</td><td>{$downloads}</td><td>{$rating}</td></tr>\n";
- }
- echo '</table>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement