Created
November 19, 2010 19:52
-
-
Save xrogaan/707034 to your computer and use it in GitHub Desktop.
powa toolz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Construit une URL en reprenant l'URL actuelle et certains de ses paramètres GET | |
si $keep est un array, seuls les éléments de $keep sont conservés | |
si $remove est un array, les éléments de $remove sont enlevés | |
si $add est un array( clé => valeur ), ces paramètres sont ajoutés à l'URL | |
exemple : | |
url actuelle : truc.php?a=1&b=2 | |
url_from_get_vars( array( 'a' ), false, array( 'c' => 3 ) ) | |
=> truc.php?a=1&c=3 | |
url_from_get_vars( false, array( 'a' ), array( 'c' => 3 ) ) | |
=> truc.php?b=2&c=3 | |
*/ | |
function url_from_get_vars( $keep=false, $remove=false, $add = array() ) | |
{ | |
$params = array(); | |
foreach( $_GET as $key => $value ) | |
if( (!$keep || in_array( $key, $keep )) && !($remove && in_array( $key, $remove )) ) | |
$params[] = $key.'='.urlencode( $value ); | |
foreach( $add as $key => $value ) | |
$params[] = $key.'='.urlencode( $value ); | |
return $_SERVER['PHP_SELF'].'?'.implode( '&', $params ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment