class_mcUrl.inc.php
1.38 KB
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
<?php
/**
* @copyright (c) 2014, netz.coop eG
*/
class mcUrl {
/**
*
* @param string $param_url example: domain.lc/?var1=1
* @param array $param_Vars example: array('var1'=>1)
* @return string
*/
public static function removeVarFromUrlstring($param_url, array $param_Vars) {
foreach($param_Vars as $key => $value) {
if(strpos($param_url, '?'.$key.'=') ) {
$seperator = '?';
} else if(strpos($param_url, '&'.$key.'=')) {
$seperator = '&';
}
$Url = substr($param_url, 0, strpos($param_url, $seperator.$key.'='.$value));
if($rest = substr($param_url, strpos($param_url, $seperator.$key.'='.$value) + strlen($seperator.$key.'='.$value))) {
if(strpos($Url, '?')===false) {
$Url = $Url.'?'.substr($rest, 1);
} else {
$Url = $Url.'&'.substr($rest, 1);
}
}
$param_url = $Url;
}
return $param_url;
}
/**
*
* @param string $param_url example: domain.lc/?var1=1
* @param array $param_Vars example: array('var1'=>1)
* @return string
*/
public static function addVarToUrlstring($param_url, array $param_Vars) {
if(strpos($param_url, '?')===false && strpos($param_url, '&')===false) {
$onekey = key($param_Vars);
$param_url .= '?'.$onekey.'='.$param_Vars[$onekey];
unset($param_Vars[$onekey]);
}
foreach($param_Vars as $key => $value) {
$param_url .= '&'.$key.'='.$value;
}
return $param_url;
}
}
?>