url

Versions
5
url($path = NULL, $query = NULL, $fragment = NULL, $absolute = FALSE)
6
url($path = NULL, $options = array())
7
url($path = NULL, array $options = array())

Generate a URL from a Drupal menu path. Will also pass-through existing URLs.

When creating links in modules, consider whether l() could be a better alternative than url().

Parameters

$path The Drupal path being linked to, such as "admin/content/node", or an existing URL like "http://drupal.org/".

$query A query string to append to the link or URL.

$fragment A fragment identifier (named anchor) to append to the link. If an existing URL with a fragment identifier is used, it will be replaced. Note, do not include the '#'.

$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

a string containing a URL to the given path.

Related topics

▾ 96 functions call url()

aggregator_help in drupal/modules/aggregator/aggregator.module
Implementation of hook_help().
aggregator_page_category in drupal/modules/aggregator/aggregator.module
Menu callback; displays all the items aggregated in a particular category.
aggregator_page_last in drupal/modules/aggregator/aggregator.module
Menu callback; displays the most recent items gathered from any feed.
aggregator_page_rss in drupal/modules/aggregator/aggregator.module
Menu callback; generate an RSS 0.92 feed of aggregator items or categories.
aggregator_page_sources in drupal/modules/aggregator/aggregator.module
Menu callback; displays all the feeds used by the aggregator.
block_admin_display in drupal/modules/block/block.module
Generate main block administration form.
block_box_form in drupal/modules/block/block.module
block_help in drupal/modules/block/block.module
Implementation of hook_help().
blogapi_blogger_get_users_blogs in drupal/modules/blogapi/blogapi.module
blogapi_blogger_get_user_info in drupal/modules/blogapi/blogapi.module
Blogging API callback. Returns profile information about a user.
blogapi_help in drupal/modules/blogapi/blogapi.module
Implementation of hook_help().
blogapi_menu in drupal/modules/blogapi/blogapi.module
blogapi_rsd in drupal/modules/blogapi/blogapi.module
blog_feed_last in drupal/modules/blog/blog.module
Displays an RSS feed containing recent blog entries of all users.
blog_feed_user in drupal/modules/blog/blog.module
Displays an RSS feed containing recent blog entries of a given user.
blog_page_last in drupal/modules/blog/blog.module
Displays a Drupal page containing recent blog entries of all users.
blog_page_user in drupal/modules/blog/blog.module
Displays a Drupal page containing recent blog entries of a given user.
book_help in drupal/modules/book/book.module
Implementation of hook_help().
color_form_alter in drupal/modules/color/color.module
Implementation of hook_form_alter().
color_help in drupal/modules/color/color.module
Implementation of hook_help
comment_admin_settings in drupal/modules/comment/comment.module
Menu callback; presents the comment settings page.
comment_form in drupal/modules/comment/comment.module
comment_nodeapi in drupal/modules/comment/comment.module
Implementation of hook_nodeapi().
contact_admin_settings in drupal/modules/contact/contact.module
contact_help in drupal/modules/contact/contact.module
Implementation of hook_help().
contact_mail_page_submit in drupal/modules/contact/contact.module
Process the site-wide contact page form submission.
contact_mail_user_submit in drupal/modules/contact/contact.module
Process the personal contact page form submission.
contact_user in drupal/modules/contact/contact.module
Implementation of hook_user().
contact_user_page in drupal/modules/contact/contact.module
Personal contact page.
drupal_goto in drupal/includes/common.inc
Send the user to a different Drupal page.
drupal_help in drupal/modules/drupal/drupal.module
Implementation of hook_help().
drupal_sites_registry_settings in drupal/modules/drupal/drupal.module
file_create_url in drupal/includes/file.inc
Create the download path to a file.
filter_help in drupal/modules/filter/filter.module
Implementation of hook_help().
forum_overview in drupal/modules/forum/forum.module
Returns an overview list of existing forums and containers
help_help in drupal/modules/help/help.module
Implementation of hook_help().
help_main in drupal/modules/help/help.module
Menu callback; prints a page listing a glossary of Drupal terminology.
install_complete in drupal/install.php
Page displayed when the installation is complete. Called from install.php.
l in drupal/includes/common.inc
Format an internal Drupal link.
locale_help in drupal/modules/locale/locale.module
Implementation of hook_help().
locale_update_1 in drupal/modules/locale/locale.install
Neutralize unsafe language names in the database.
menu_configure in drupal/modules/menu/menu.module
Menu callback; presents menu configuration options.
menu_form_alter in drupal/modules/menu/menu.module
Implementation of hook_form_alter(). Add menu item fields to the node form.
menu_get_active_help in drupal/includes/menu.inc
Returns the help associated with the active menu item.
menu_help in drupal/modules/menu/menu.module
Implementation of hook_help().
node_admin_search in drupal/modules/node/node.module
node_block in drupal/modules/node/node.module
Implementation of hook_block().
node_feed in drupal/modules/node/node.module
A generic function for generating RSS feeds from a set of nodes.
node_page_default in drupal/modules/node/node.module
Menu callback; Generate a listing of promoted nodes.
node_search in drupal/modules/node/node.module
Implementation of hook_search().
path_form in drupal/modules/path/path.module
Return a form for editing or creating an individual URL alias.
phptemplate_node in drupal/themes/engines/phptemplate/phptemplate.engine
Prepare the values passed to the theme_node function to be passed into a pluggable template engine.
poll_cancel_form in drupal/modules/poll/poll.module
poll_help in drupal/modules/poll/poll.module
Implementation of hook_help().
poll_view_voting in drupal/modules/poll/poll.module
Generates the voting form for a poll.
profile_block in drupal/modules/profile/profile.module
Implementation of hook_block().
profile_field_delete in drupal/modules/profile/profile.module
Menu callback; deletes a field from all user profiles.
search_form in drupal/modules/search/search.module
Render a search form.
statistics_access_log in drupal/modules/statistics/statistics.module
statistics_help in drupal/modules/statistics/statistics.module
Implementation of hook_help().
system_error_reporting_settings in drupal/modules/system/system.module
system_help in drupal/modules/system/system.module
Implementation of hook_help().
system_main_admin_page in drupal/modules/system/system.module
Provide the administration overview page.
system_modules in drupal/modules/system/system.module
Menu callback; provides module enable/disable interface.
system_modules_uninstall in drupal/modules/system/system.module
Builds a form of currently disabled modules.
system_requirements in drupal/modules/system/system.install
Test and report Drupal installation requirements.
system_site_information_settings in drupal/modules/system/system.module
system_site_maintenance_settings in drupal/modules/system/system.module
system_themes_submit in drupal/modules/system/system.module
system_update_177 in drupal/modules/system/system.install
taxonomy_form_term in drupal/modules/taxonomy/taxonomy.module
taxonomy_form_vocabulary in drupal/modules/taxonomy/taxonomy.module
Display form for adding and editing vocabularies.
taxonomy_rss_item in drupal/modules/taxonomy/taxonomy.module
Provides category information for RSS feeds.
taxonomy_term_page in drupal/modules/taxonomy/taxonomy.module
Menu callback; displays all nodes associated with a term.
theme_book_navigation in drupal/modules/book/book.module
Prepares the links to children (TOC) and forward/backward navigation for a node presented as a book page.
theme_comment_post_forbidden in drupal/modules/comment/comment.module
theme_forum_display in drupal/modules/forum/forum.module
Format the forum body.
theme_image in drupal/includes/theme.inc
Return a themed image.
theme_textfield in drupal/includes/form.inc
Format a textfield.
upload_form_alter in drupal/modules/upload/upload.module
upload_help in drupal/modules/upload/upload.module
Implementation of hook_help().
upload_nodeapi in drupal/modules/upload/upload.module
Implementation of hook_nodeapi().
user_admin in drupal/modules/user/user.module
user_help in drupal/modules/user/user.module
Implementation of hook_help().
user_login_block in drupal/modules/user/user.module
user_login_validate in drupal/modules/user/user.module
user_pass_reset in drupal/modules/user/user.module
Menu callback; process one time login link and redirects to the user page on success.
user_pass_reset_url in drupal/modules/user/user.module
user_pass_submit in drupal/modules/user/user.module
user_register in drupal/modules/user/user.module
user_register_submit in drupal/modules/user/user.module
user_search in drupal/modules/user/user.module
Implementation of hook_search().
_blogapi_get_post in drupal/modules/blogapi/blogapi.module
_locale_add_language in drupal/includes/locale.inc
Helper function to add a language
_upload_form in drupal/modules/upload/upload.module
_user_edit_validate in drupal/modules/user/user.module

Code

drupal/includes/common.inc, line 1293

<?php
function url($path = NULL, $query = NULL, $fragment = NULL, $absolute = FALSE) {
  if (isset($fragment)) {
    $fragment = '#'. $fragment;
  }

  // Return an external link if $path contains an allowed absolute URL.
  // Only call the slow filter_xss_bad_protocol if $path contains a ':' before any / ? or #.
  $colonpos = strpos($path, ':');
  if ($colonpos !== FALSE && !preg_match('![/?#]!', substr($path, 0, $colonpos)) && filter_xss_bad_protocol($path, FALSE) == check_plain($path)) {
    // Split off the fragment
    if (strpos($path, '#') !== FALSE) {
      list($path, $old_fragment) = explode('#', $path, 2);
      if (isset($old_fragment) && !isset($fragment)) {
        $fragment = '#'. $old_fragment;
      }
    }
    // Append the query
    if (isset($query)) {
      $path .= (strpos($path, '?') !== FALSE ? '&' : '?') . $query;
    }
    // Reassemble
    return $path . $fragment;
  }

  global $base_url;
  static $script;
  static $clean_url;

  if (!isset($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' : '';
  }

  // Cache the clean_url variable to improve performance.
  if (!isset($clean_url)) {
    $clean_url = (bool)variable_get('clean_url', '0');
  }

  $base = ($absolute ? $base_url . '/' : base_path());

  // The special path '<front>' links to the default front page.
  if (!empty($path) && $path != '<front>') {
    $path = drupal_get_path_alias($path);
    $path = drupal_urlencode($path);
    if (!$clean_url) {
      if (isset($query)) {
        return $base . $script .'?q='. $path .'&'. $query . $fragment;
      }
      else {
        return $base . $script .'?q='. $path . $fragment;
      }
    }
    else {
      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;
    }
  }
}
?>

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters (without spaces) shown in the image.