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: 8 years ago
Size: 1,246 bytes
 

Contents

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

$urlbuilder = urlbuilder::CreateNew();

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

//Gets the array used internally for storing the data
var_dump($urlbuilder->GetArray());

//Builds the URL
var_dump($urlbuilder->GetLink());

//Build a rewrite rule for the link, NOTE: you will need to add the file name to the url rule
var_dump($urlbuilder->GetRewriteRule());

//Example Output
/*
array (size=5)
  'BaseURL' => string 'http://example.com/' (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 'http://example.com/news/year/2015/news-slug/' (length=44)

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

*/

?>