<?php use HttpStub\Storage\FileStorage; require_once __DIR__ . '/config.php'; require_once 'functions.php'; $storage = new FileStorage('posts'); $category = getValue($_GET, 'category'); $data = $storage->readAll(); $data = (array) $data; end($data); //moving the internal pointer to the last element of the array $last = key($data); //getting the value of the index of the last element of the array require 'views/header.php'; require 'views/browse.php'; require 'views/footer.php';
<?php use HttpStub\Storage\FileStorage; require_once __DIR__ . '/config.php'; require_once 'functions.php'; $blogDate = date("d.m.Y H:i"); $blogsStorage = new FileStorage('blogs'); $subjectsStorage = new FileStorage('subjects'); $subjects = $subjectsStorage->readAll(); $data = []; $errors = []; if ($_POST) { $data = $_POST; if (!getValue($data, 'title') || mb_strlen(getValue($data, 'title'), 'UTF-8') < 5) { $errors[] = 'Title at last 5 characters is required'; } if (!getValue($data, 'text')) { $errors[] = 'Text is required'; } if (!$errors) { $blogsStorage->insert($data); header('Location: blogs.php'); die; } } $data = (array) $data; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8">