Advertisement
Guest User

03.FacebookPosts

a guest
Sep 6th, 2014
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1. <?php
  2. date_default_timezone_set("Europe/Sofia");
  3. $text = $_GET['text'];
  4. $articles = preg_split('/\s*\n/', $text, -1, PREG_SPLIT_NO_EMPTY);
  5.  
  6. $articleDetails = [];
  7. foreach ($articles as $article) {
  8.     $articleDetails[] = preg_split('/\s*;\s*/', $article , -1, PREG_SPLIT_NO_EMPTY);
  9. }
  10.  
  11. //sort by date
  12. usort($articleDetails, function($a, $b) {
  13.     return strtotime($a[1]) < strtotime($b[1]) ? 1 : -1;
  14. });
  15.  
  16. $output = "";
  17. for ($i = 0; $i < count($articleDetails); $i++) {
  18.     $date = strtotime($articleDetails[$i][1]);
  19.     $date = date("j F Y", $date);
  20.     $output .= "<article><header>";
  21.     $output .= "<span>" . htmlspecialchars($articleDetails[$i][0]) . "</span>";
  22.     $output .= "<time>" . $date . "</time></header>";
  23.     $output .= "<main><p>" . htmlspecialchars($articleDetails[$i][2]) . "</p></main>";
  24.     $output .= "<footer><div class=\"likes\">" . htmlspecialchars($articleDetails[$i][3]) . " people like this</div>";
  25.     //check if there are any comments
  26.     if (isset($articleDetails[$i][4])) {
  27.         $comments = explode('/', $articleDetails[$i][4]);
  28.         $output .= "<div class=\"comments\">";
  29.         for ($j = 0; $j < count($comments); $j++) {
  30.             $output .= "<p>" . htmlspecialchars(trim($comments[$j])) . "</p>";
  31.         }
  32.         $output .= "</div>";
  33.     }
  34.     $output .= "</footer></article>";
  35. }
  36. echo $output;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement