PHP Classes

PHP URL Builder: Build friendly URLs and generate mod_rewrite rules

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStar 57%Total: 319 All time: 7,239 This week: 488Up
Version License PHP version Categories
url-builder 1.0.0MIT/X Consortium ...5.0HTML, PHP 5, SEO
Description 

Author

This class can build friendly URLs and generate mod_rewrite rules.

It can take a base URL and add parameter values to it to build a friendly URL separating the values with slashes /.

The class can also build mod_rewrite URL rules to map friendly URLs to regular URLs using GET parameters.

Picture of Nathan John Pipes
  Performance   Level  
Name: Nathan John Pipes <contact>
Classes: 1 package by
Country: Australia Australia

Example

<?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)

*/

?>


  Files folder image Files (2)  
File Role Description
Accessible without login Plain text file example.php Example Example and how to use
Plain text file urlbuilder.class.php Class UrlBuilder Class

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:319
This week:0
All time:7,239
This week:488Up
 User Ratings  
 
 All time
Utility:83%StarStarStarStarStar
Consistency:75%StarStarStarStar
Documentation:-
Examples:83%StarStarStarStarStar
Tests:-
Videos:-
Overall:57%StarStarStar
Rank:1679