PHP code example of profmugomes / miphantroute

1. Go to this page and download the library: Download profmugomes/miphantroute 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/ */

    

profmugomes / miphantroute example snippets


use MiPhantRoute\MiPhantRoute;

$route = new MiPhantRoute();

$route->getPart('/', function () {
    echo 'Página inicial';
});

$route->getPart('/contato', function () {
    echo 'Página de contato';
});

$route->getError(function () {
    http_response_code(404);
    echo '404 - Página não encontrada';
});

[
  '/blog/post/123',
  ['blog', 'post', '123']
]

$route->getPart('/blog', function () {
    echo 'Página do blog';
});

$route->getPart('/blog/post/([0-9]+)', function ($id) {
    echo "Post ID: {$id}";
});

$route->getPart('/user/([a-z]+)/([0-9]+)', function ($username, $id) {
    echo "Usuário: {$username} | ID: {$id}";
});

$route->getArrayURLs();
// ['blog', 'post', '123']

$route->getFullURL();
// blog/post/123

$route->getURL(0); // blog
$route->getURL(1); // post
$route->getURL(2); // 123

$route->getFirstURL(); // blog

$route->getPenultimateURL(); // post

$route->getLastURL(); // 123

$route->getError(function () {
    http_response_code(404);
    echo 'Página não encontrada';
});
ini
ini_set('pcre.jit', 0);