Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- date_default_timezone_set("Europe/Sofia");
- $text = $_GET['text'];
- $articles = preg_split('/\s*\n/', $text, -1, PREG_SPLIT_NO_EMPTY);
- $articleDetails = [];
- foreach ($articles as $article) {
- $articleDetails[] = preg_split('/\s*;\s*/', $article , -1, PREG_SPLIT_NO_EMPTY);
- }
- //sort by date
- usort($articleDetails, function($a, $b) {
- return strtotime($a[1]) < strtotime($b[1]) ? 1 : -1;
- });
- $output = "";
- for ($i = 0; $i < count($articleDetails); $i++) {
- $date = strtotime($articleDetails[$i][1]);
- $date = date("j F Y", $date);
- $output .= "<article><header>";
- $output .= "<span>" . htmlspecialchars($articleDetails[$i][0]) . "</span>";
- $output .= "<time>" . $date . "</time></header>";
- $output .= "<main><p>" . htmlspecialchars($articleDetails[$i][2]) . "</p></main>";
- $output .= "<footer><div class=\"likes\">" . htmlspecialchars($articleDetails[$i][3]) . " people like this</div>";
- //check if there are any comments
- if (isset($articleDetails[$i][4])) {
- $comments = explode('/', $articleDetails[$i][4]);
- $output .= "<div class=\"comments\">";
- for ($j = 0; $j < count($comments); $j++) {
- $output .= "<p>" . htmlspecialchars(trim($comments[$j])) . "</p>";
- }
- $output .= "</div>";
- }
- $output .= "</footer></article>";
- }
- echo $output;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement