Commit 0cbaad8c by sn

Url klasse 2

1 parent e03b8769
Showing with 49 additions and 0 deletions
<?php
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;
}
}
?>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!