Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- date_default_timezone_set('Europe/Sofia');
- $text = $_GET['text'];
- $postPattern = "/\s*(.+?)\s*;\s*(\d{1,2}\-\d{1,2}\-\d{4})\s*;\s*(.+?)\s*;\s*(\d{1,4})\s*;\s*(.*)\s*/";
- preg_match_all($postPattern, $text, $matches, PREG_SET_ORDER);
- $resultPosts = array();
- foreach ($matches as $match) {
- $author = htmlspecialchars($match[1]);
- $post = htmlspecialchars($match[3]);
- $likesCount = (int)$match[4];
- $comments = preg_split('/\s*\/\s*/', $match[5], -1, PREG_SPLIT_NO_EMPTY);
- $time = strtotime($match[2]);
- $date = date("j F Y", $time);
- $resultPosts[$time] = array($author, $date, $post, $likesCount, $comments);
- }
- krsort($resultPosts);
- foreach ($resultPosts as $postInfo) {
- echo "<article><header><span>{$postInfo[0]}</span><time>{$postInfo[1]}</time></header>";
- echo "<main><p>{$postInfo[2]}</p></main><footer><div class=\"likes\">{$postInfo[3]} people like this</div>";
- if (count($postInfo[4]) > 0) {
- echo '<div class="comments">';
- foreach ($postInfo[4] as $comment) {
- echo '<p>' . htmlspecialchars(trim($comment)) . '</p>';
- }
- echo '</div>';
- }
- echo '</footer></article>';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement