Piwik\

UrlHelper

Contains less commonly needed URL helper methods.

Methods

The class defines the following methods:

getQueryStringWithExcludedParameters()

Converts an array of query parameter name/value mappings into a query string.

Parameters that are in $parametersToExclude will not appear in the result.

Signature

  • It accepts the following parameter(s):

    • $queryParameters Array of query parameters, eg, array('site' => '0', 'date' => '2012-01-01').
    • $parametersToExclude Array of query parameter names that shouldn't be in the result query string, eg, array('date', 'period').
  • Returns: string — A query string, eg, "?site=0".

isLookLikeUrl()

Returns true if the string passed may be a URL ie. it starts with protocol://.

We don't need a precise test here because the value comes from the website tracked source code and the URLs may look very strange.

Signature

  • It accepts the following parameter(s):

    • $url (string) —
  • It returns a bool value.

getParseUrlReverse()

Returns a URL created from the result of the parse_url function.

Copied from the PHP comments at http://php.net/parse_url.

Signature

  • It accepts the following parameter(s):

  • Returns: false|string — The URL or false if $parsed isn't an array.

getArrayFromQueryString()

Returns a URL query string as an array.

Signature

  • It accepts the following parameter(s):

    • $urlQuery (string) — The query string, eg, '?param1=value1&param2=value2'.
  • Returns: array — eg, array('param1' => 'value1', 'param2' => 'value2')

getParameterFromQueryString()

Returns the value of a single query parameter from the supplied query string.

Signature

  • It accepts the following parameter(s):

    • $urlQuery (string) — The query string.
    • $parameter (string) — The query parameter name to return.
  • Returns: string|null — Parameter value if found (can be the empty string!), null if not found.

getPathAndQueryFromUrl()

Returns the path and query string of a URL.

Signature

  • It accepts the following parameter(s):

    • $url (string) — The URL.
    • $additionalParamsToAdd (array) — If not empty the given parameters will be added to the query.
    • $preserveAnchor (bool) — If true then do not remove any #anchor from the url, default false
  • Returns: string — eg, /test/index.php?module=CoreHome if $url is http://piwik.org/test/index.php?module=CoreHome.

getQueryFromUrl()

Returns the query part from any valid url and adds additional parameters to the query part if needed.

Signature

  • It accepts the following parameter(s):

    • $url (string) — Any url eg "http://example.com/piwik/?foo=bar"
    • $additionalParamsToAdd (array) — If not empty the given parameters will be added to the query.
  • Returns: string — eg. "foo=bar&foo2=bar2"