PHP code example of fastpress / router

1. Go to this page and download the library: Download fastpress/router library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fastpress / router example snippets




$router = new Fastpress\Routing\Router();

// Define a GET route
$router->get('/home', function() {
    return 'Welcome to the homepage!';
});

// Handle the request
// Assuming $server and $post are your $_SERVER and $_POST variables
$result = $router->match($server, $post);

if ($result) {
    // Route was matched
    list($args, $callable) = $result;
    call_user_func_array($callable, $args);
} else {
    // No route was matched
    header("HTTP/1.0 404 Not Found");
}

$router->get($uri, $callable);
$router->post($uri, $callable);
$router->put($uri, $callable);
$router->delete($uri, $callable);