Function Reference: geodir_getlink

Summary

Return a formatted link with parameters.

Description

Returns a link with new parameters and currently used parameters regardless of ? or & in the $url parameter.

Package

GeoDirectory

Parameters

$url
(string) (required) The main url to be used.

Default: None
$params
(array) (required) The arguments array.

Default: None
$use_existing_arguments
(bool) (required) Do you want to use existing arguments? Default: false.

Default: None

Return Values

(string)
  • Formatted link.

Change Log

Since: 1.0.0

Source File

geodir_getlink() is located in geodirectory-functions/general_functions.php [Line: 129]

Source Code

function geodir_getlink( $url, $params = array(), $use_existing_arguments = false ) {
	if ( $use_existing_arguments ) {
		$params = $params + $_GET;
	}
	if ( ! $params ) {
		return $url;
	}
	$link = $url;
	if ( strpos( $link, '?' ) === false ) {
		$link .= '?';
	} //If there is no '?' add one at the end
	elseif ( strpos( $link, '//maps.google.com/maps/api/js?language=' ) ) {
		$link .= '&';
	} //If there is no '&' at the END, add one.
	elseif ( ! preg_match( '/(\?|\&(amp;)?)$/', $link ) ) {
		$link .= '&';
	} //If there is no '&' at the END, add one.

	$params_arr = array();
	foreach ( $params as $key => $value ) {
		if ( gettype( $value ) == 'array' ) { //Handle array data properly
			foreach ( $value as $val ) {
				$params_arr[] = $key . '[]=' . urlencode( $val );
			}
		} else {
			$params_arr[] = $key . '=' . urlencode( $value );
		}
	}
	$link .= implode( '&', $params_arr );

	return $link;
}