route.class.php 最简单轻量的url路由,支持正反向url解析免费下载

【资源属性】:
资源名称:route.class.php 最简单轻量的url路由,支持正反向url解析
资源大小:6KB
资源类别: 源码下载php源码
更新时间:2023-02-02
资源语言:简体中文
授权方式:免费下载
使用平台:Windows/Linux/Mac
下载地址:下载地址
资源介绍:

最简单轻量的php url路由,支持正反向解析,如果亲正在组建自己的框架或者工具库可以考虑。仓鼠出品,必优.

[code]
<?php
require_once __DIR__ . '/route.class.php';

function index_init()
{
    error_reporting(E_ALL | E_STRICT);
    header("Content-Type: text/html;charset=utf-8");

    $arr = array(
            '/index.html',
            '/student/index.html',
            '/student/user/index.html',
            '/student/user/role/index///.html',

            '/index.xml',
            '/student/index.xml',
            '/student/user/index.xml',
            '/student/user/role/index///.xml',

            '/index.jsonp',
            '/student/index.jsonp',
            '/student/user/index.jsonp',
            '/student/user/role/index.jsonp',

            '/index.json',
            '/student/index.json',
            '/student/user/index.json',
            '/student/user/role/index.jsonp',

        );

    foreach( $arr as $t )
    {
        Route::parse_url($t);
        prety_printr($_GET);
        $route_key = $_GET['q:route'];
        unset($_GET['q:route']);
        prety_printr( Route::rewrite_url($route_key, $_GET));
    }

    echo __FILE__;
    EXIT;
}


function prety_printr($vars, $label = '', $return = false)
{
    $content = "<pre>\n";
    if ($label != '') {
        $content .= "<strong>{$label} :</strong>\n";
    }
    $content .= htmlspecialchars(print_r($vars, true),ENT_COMPAT | ENT_IGNORE);
    $content .= "\n</pre>\n";

    if ($return) { return $content; }
    echo $content;
}

index_init();
[/code]

资源标签: url路由