PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Nathan John Pipes   PHP URL Builder   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example and how to use
Class: PHP URL Builder
Build friendly URLs and generate mod_rewrite rules
Author: By
Last change: Added Trailing slash on Base URL
Date: 7 years ago
Size: 1,246 bytes


Class file image Download
require "urlbuilder.class.php";

$urlbuilder = urlbuilder::CreateNew();

//Supports chaining to make things easier, order does NOT matter
$urlbuilder->BaseURL("")->Set("year", "2015", false)->Set("slug", "news-slug", true)->Prefix("news")->Seperator("/")->Suffix("/");

//Gets the array used internally for storing the data

//Builds the URL

//Build a rewrite rule for the link, NOTE: you will need to add the file name to the url rule

//Example Output
array (size=5)
  'BaseURL' => string '' (length=19)
  'Params' =>
    array (size=2)
      'year' =>
        array (size=2)
          'Value' => string '2015' (length=4)
          'HideKey' => boolean false
      'slug' =>
        array (size=2)
          'Value' => string 'news-slug' (length=9)
          'HideKey' => boolean true
  'Prefix' => string 'news' (length=4)
  'Seperator' => string '/' (length=1)
  'Suffix' => string '/' (length=1)

string '' (length=44)

string 'news/year/([^/]*)/([^/]*)\/$ ?year=$1&slug=$1' (length=45)