Same name and namespace in other branches
- 4.7.x includes/common.inc \url()
- 5.x includes/common.inc \url()
- 6.x includes/common.inc \url()
- 7.x includes/common.inc \url()
Generate an internal Drupal URL.
Parameters
$path: The Drupal path being linked to, such as "admin/node".
$query: A query string to append to the link.
$fragment: A fragment identifier (named anchor) to append to the link.
$absolute: Whether to force the output to be an absolute link (beginning with http:). Useful for links that will be displayed outside the site, such as in an RSS feed.
Return value
an HTML string containing a link to the given path.
When creating links in modules, consider whether l() could be a better alternative than url().
Related topics
45 calls to url()
- aggregator_page_sources in modules/
aggregator.module - Menu callback; displays all the feeds used by the aggregator.
- block_admin_display in modules/
block.module - Prepare the main block administration form.
- block_box_form in modules/
block.module - blogapi_blogger_get_users_blogs in modules/
blogapi.module - Blogging API callback. Finds the URL of a user's blog.
- blogapi_blogger_get_user_info in modules/
blogapi.module - Blogging API callback. Returns profile information about a user.
3 string references to 'url'
- aggregator_form_feed in modules/
aggregator.module - statistics_top_referrers in modules/
statistics.module - Menu callback; presents the "Top referrers" page.
- update_80 in database/
updates.inc
File
- includes/
common.inc, line 1462 - Common functions that many Drupal modules will need to reference.
Code
function url($path = NULL, $query = NULL, $fragment = NULL, $absolute = FALSE) {
global $base_url;
static $script;
if (empty($script)) {
// On some web servers, such as IIS, we can't omit "index.php". So, we
// generate "index.php?q=foo" instead of "?q=foo" on anything that is not
// Apache.
$script = strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') === false ? 'index.php' : '';
}
$path = drupal_get_path_alias($path);
if (isset($fragment)) {
$fragment = '#' . $fragment;
}
$base = $absolute ? $base_url . '/' : '';
if (variable_get('clean_url', '0') == '0') {
if (isset($path)) {
if (isset($query)) {
return $base . $script . '?q=' . $path . '&' . $query . $fragment;
}
else {
return $base . $script . '?q=' . $path . $fragment;
}
}
else {
if (isset($query)) {
return $base . $script . '?' . $query . $fragment;
}
else {
return $base . $fragment;
}
}
}
else {
if (isset($path)) {
if (isset($query)) {
return $base . $path . '?' . $query . $fragment;
}
else {
return $base . $path . $fragment;
}
}
else {
if (isset($query)) {
return $base . $script . '?' . $query . $fragment;
}
else {
return $base . $fragment;
}
}
}
}