Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- date_default_timezone_set('Europe/Sofia');
- $text = trim($_GET['text']);
- $postsList = preg_split('/\r?\n/', $text, -1, PREG_SPLIT_NO_EMPTY);
- $posts = array();
- $result = '';
- foreach ($postsList as $key => $p) {
- $post = explode(';', $p);
- $commentsStr = '';
- $posts[$key]['name'] = trim($post[0]);
- $posts[$key]['time'] = strtotime(trim($post[1]));
- $posts[$key]['post'] = trim($post[2]);
- $posts[$key]['likes'] = trim($post[3]);
- if ($post[4]) {
- $com = explode('/', $post[4]);
- $comments = '';
- foreach ($com as $c) {
- $comments .= '<p>' . htmlspecialchars(trim($c)) . '</p>';
- }
- $commentsStr = '<div class="comments">' . $comments . '</div>';
- }
- $posts[$key]['comments'] = $commentsStr;
- }
- $posts = multisort($posts, SORT_DESC, 'time');
- foreach($posts as $post) {
- $result .= '<article>';
- $result .= '<header><span>' . htmlspecialchars($post['name']) . '</span><time>' . date('j F Y', $post['time']) . '</time></header>';
- $result .= '<main><p>' . htmlspecialchars($post['post']) . '</p></main>';
- $result .= '<footer><div class="likes">' . htmlspecialchars($post['likes']) . ' people like this</div>' . $post['comments'] . '</footer>';
- $result .= '</article>';
- }
- echo $result;
- function multisort($arr, $ord, $property) {
- foreach ($arr as $id => $val) {
- $key[$id] = $val[$property];
- }
- array_multisort($key, $ord, $arr);
- return $arr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement