You are here

function front_page_parse_url in Front Page 8

Same name and namespace in other branches
  1. 6.2 front_page.module \front_page_parse_url()
  2. 7.2 front_page.module \front_page_parse_url()
  3. 7 front_page.module \front_page_parse_url()
  4. 9.1.x front_page.module \front_page_parse_url()

Parse URL including GET and fragment.

Function to parse a full URL including GET variables and fragment to an array ready for drupal_goto(), url(), or l() functions.

File

./front_page.module, line 37
This module allows the site admin to set advanced front page settings.

Code

function front_page_parse_url($path) {
  $url['path'] = $path;
  $url['options'] = [];
  if (preg_match('@^(?P<path>[^?#]+)(\\?(?P<query>[^#]*))?(#(?P<fragment>.*))?$@', $path, $match)) {
    $url['path'] = $match['path'];
    if (!empty($match['query'])) {
      foreach (explode('&', $match['query']) as $query_part) {
        list($key, $value) = explode('=', $query_part);
        $url['options']['query'][$key] = $value;
      }
    }
    if (!empty($match['fragment'])) {
      $url['options']['fragment'] = $match['fragment'];
    }
  }
  return $url;
}