PHP Classes

PHP URL Builder: Build friendly URLs and generate mod_rewrite rules

Recommend this page to a friend!
  Info   View files Example   View files View files (2)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStar 57%Total: 319 All time: 7,237 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
Age: 30
All time rank: 377745 in Australia Australia
Week rank: 286 Up3 in Australia Australia Up

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

 Version Control Unique User Downloads Download Rankings  
 0%
Total:319
This week:0
All time:7,237
This week:488Up
 User Ratings  
 
 All time
Utility:83%StarStarStarStarStar
Consistency:75%StarStarStarStar
Documentation:-
Examples:83%StarStarStarStarStar
Tests:-
Videos:-
Overall:57%StarStarStar
Rank:1668