-
-
Save illucent/9857041 to your computer and use it in GitHub Desktop.
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 | |
// Get and sanitize the current URL | |
function _s_get_url() { | |
// Get URL | |
$url = @( $_SERVER['HTTPS'] != 'on' ) ? 'http://' . $_SERVER['SERVER_NAME'] : 'https://' . $_SERVER['SERVER_NAME']; | |
$url .= ( $_SERVER['SERVER_PORT'] !== 80 ) ? ":" . $_SERVER['SERVER_PORT'] : ''; | |
$url .= $_SERVER['REQUEST_URI']; | |
return $url; | |
} | |
// Get the site domain and remove the www. | |
function _s_get_site_domain() { | |
$sitename = strtolower( $_SERVER['SERVER_NAME'] ); | |
if ( substr( $domain, 0, 4 ) == 'www.' ) { | |
$sitename = substr( $sitename, 4 ); | |
} | |
return $sitename; | |
} | |
// Prepare URL for status string | |
function _s_prepare_url( $url ) { | |
// If URL has a '?', add an '&'. | |
// Otherwise, add a '?'. | |
$url_status = strpos($url, '?'); | |
if ( $url_status === false ) { | |
$concate = '?'; | |
} | |
else { | |
$concate = '&'; | |
} | |
return $url . $concate; | |
} | |
// Remove a $_GET variable from the URL | |
function _s_clean_url( $variable, $url ) { | |
$new_url = preg_replace('/(?:&|(\?))' . $variable . '=[^&]*(?(1)&|)?/i', '$1', $url); | |
$last_char = substr( $new_url, -1 ); | |
if ( $last_char == '?' ) { | |
$new_url = substr($new_url, 0, -1); | |
} | |
return $new_url; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment