You are here

protected function FeedsCrawler::baseUrl in Feeds Crawler 7

Same name and namespace in other branches
  1. 6.2 FeedsCrawler.inc \FeedsCrawler::baseUrl()

Breaks a url up removing everything but the http://example.com.

Parameters

string $url: The url string to return the base path for.

bool $relative: (Optional) If TRUE, returns the base path as well fir relative urls. Defaults to FALSE.

1 call to FeedsCrawler::baseUrl()
FeedsCrawler::parseHref in ./FeedsCrawler.inc
Builds a fully qualified URL from the source URL if necessary.

File

./FeedsCrawler.inc, line 144
Home of the FeedsCrawler.

Class

FeedsCrawler
Fetches data via HTTP.

Code

protected function baseUrl($url, $relative = FALSE) {
  $p = parse_url($url);
  $output = '';
  $output .= isset($p['scheme']) ? $p['scheme'] : 'http';
  $output .= '://';
  $output .= isset($p['user']) ? $p['user'] : '';
  $output .= isset($p['pass']) ? ':' . $p['pass'] : '';
  $output .= isset($p['user']) ? '@' : '';
  $output .= $p['host'];
  $output .= isset($p['port']) ? ':' . $p['port'] : '';
  if ($relative) {
    $output .= isset($p['path']) ? substr($p['path'], 0, strrpos($p['path'], '/')) : '';
  }
  return $output;
}