You are here

function _link_parse_url in Link 7

Because parse_url doesn't work with relative urls.

Parameters

string $url: URL to parse.

Return value

array Array of url pieces - only 'url', 'query', and 'fragment'.

3 calls to _link_parse_url()
LinkUnitTestCase::testLinkParseUrl in tests/LinkUnitTestCase.test
Test _link_parse_url().
theme_link_formatter_link_separate in ./link.module
Formats a link as separate title and URL elements.
_link_sanitize in ./link.module
Clean up user-entered values for a link field according to field settings.

File

./link.module, line 898
Defines simple link field types.

Code

function _link_parse_url($url) {
  $url_parts = array();

  // Separate out the anchor, if any.
  if (strpos($url, '#') !== FALSE) {
    $url_parts['fragment'] = substr($url, strpos($url, '#') + 1);
    $url = substr($url, 0, strpos($url, '#'));
  }

  // Separate out the query string, if any.
  if (strpos($url, '?') !== FALSE) {
    $query = substr($url, strpos($url, '?') + 1);
    $url_parts['query'] = _link_parse_str($query);
    $url = substr($url, 0, strpos($url, '?'));
  }
  $url_parts['url'] = $url;
  return $url_parts;
}