url-rewriting-class
HET .htaccess BESTAND .htaccess
Code (php)
1
2
3
4
2
3
4
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1
HET PHP BESTAND class.url.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/*************************************
= URL Engine door Harm Wellink =======
= Versie: 0.2B ===== [email protected] =
= Datum: 09-08-08 = www.harmweb.nl ==
**************************************/
/******************************************************
Deze URL Engine is het best te
gebruiken met het bijgeleverde .htaccess bestand. Lees
de site of de leesmij voor meer info
* * * * * * *
Dit script is vrij te gebruiken zolang
mijn informatie helemaal bovenaan
blijft staan!
********************************************************/
class URLEngine
{
private $URLInfo;
private $URLItems;
private $URLSplit;
public function __construct( $teken = "/" )
{
$this->URLInfo = trim( $_SERVER[ 'PATH_INFO' ] );
$this->URLItems = explode( $teken , $this->URLInfo );
$this->URLSplit = $teken;
}
public function getProperty( $number )
{
if ( $number < 0 )
{
$number = abs( $number );
if ( count ( $this->URLItems ) < $number )
{
return $this->URLItems;
}
else
{
return $this->URLItems[ count ( $this->URLItems ) - $number ];
}
}
elseif ( count( $this->URLItems ) >= $number )
{
return $this->URLItems[$number];
}
else
{
return $this->URLItems;
}
}
public function getPropertyValue( $variableName , $isSign , $expression = false)
{
if ( $isSign != $this->URLSplit )
{
foreach ( $this->URLItems as $item )
{
$func = ( $expression ? "split" : "explode" );
$itemsplit = $func( $isSign , $item , 2 );
if (( count ( $itemsplit ) == 2 ) && ( $itemsplit[0] == $variableName ))
{
$return .= $itemsplit[1]."<br />";
}
}
}
else
{
foreach ( $this->URLItems as $key => $item )
{
if ( $item == $variableName )
{
$return = $this->URLItems[ $key + 1 ];
}
}
}
return $return;
}
}
?>
/*************************************
= URL Engine door Harm Wellink =======
= Versie: 0.2B ===== [email protected] =
= Datum: 09-08-08 = www.harmweb.nl ==
**************************************/
/******************************************************
Deze URL Engine is het best te
gebruiken met het bijgeleverde .htaccess bestand. Lees
de site of de leesmij voor meer info
* * * * * * *
Dit script is vrij te gebruiken zolang
mijn informatie helemaal bovenaan
blijft staan!
********************************************************/
class URLEngine
{
private $URLInfo;
private $URLItems;
private $URLSplit;
public function __construct( $teken = "/" )
{
$this->URLInfo = trim( $_SERVER[ 'PATH_INFO' ] );
$this->URLItems = explode( $teken , $this->URLInfo );
$this->URLSplit = $teken;
}
public function getProperty( $number )
{
if ( $number < 0 )
{
$number = abs( $number );
if ( count ( $this->URLItems ) < $number )
{
return $this->URLItems;
}
else
{
return $this->URLItems[ count ( $this->URLItems ) - $number ];
}
}
elseif ( count( $this->URLItems ) >= $number )
{
return $this->URLItems[$number];
}
else
{
return $this->URLItems;
}
}
public function getPropertyValue( $variableName , $isSign , $expression = false)
{
if ( $isSign != $this->URLSplit )
{
foreach ( $this->URLItems as $item )
{
$func = ( $expression ? "split" : "explode" );
$itemsplit = $func( $isSign , $item , 2 );
if (( count ( $itemsplit ) == 2 ) && ( $itemsplit[0] == $variableName ))
{
$return .= $itemsplit[1]."<br />";
}
}
}
else
{
foreach ( $this->URLItems as $key => $item )
{
if ( $item == $variableName )
{
$return = $this->URLItems[ $key + 1 ];
}
}
}
return $return;
}
}
?>
Voorbeeldje in gebruik:
Code (php)
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
<?php
require_once "class.url.php";
$engine = new URLEngine();
//Standaard is URLEngine("/") --> Dat is ook wat ik wil in dit voorbeeld ;)
echo $engine->getParameter(-1);
echo "<br />";
echo $engine->getParameterValue("phphulper","[-:;]",true);
?>
require_once "class.url.php";
$engine = new URLEngine();
//Standaard is URLEngine("/") --> Dat is ook wat ik wil in dit voorbeeld ;)
echo $engine->getParameter(-1);
echo "<br />";
echo $engine->getParameterValue("phphulper","[-:;]",true);
?>
Op een url als bijvoorbeeld: www.jouwsite.nl/nieuwspagina/phphulper-ja/132 geeft hij als output: