url

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

Generate an internal Drupal URL.

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/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.

Related topics

▾ 73 functions call url()

aggregator_help in modules/aggregator.module
Implementation of hook_help().
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
block_help in modules/block.module
Implementation of hook_help().
blogapi_blogger_get_users_blogs in modules/blogapi.module
blogapi_blogger_get_user_info in modules/blogapi.module
Blogging API callback. Returns profile information about a user.
blogapi_menu in modules/blogapi.module
blogapi_rsd in modules/blogapi.module
blog_feed_last in modules/blog.module
Displays an RSS feed containing recent blog entries of all users.
blog_feed_user in modules/blog.module
Displays an RSS feed containing recent blog entries of a given user.
blog_page_last in modules/blog.module
Displays a Drupal page containing recent blog entries of all users.
blog_page_user in modules/blog.module
Displays a Drupal page containing recent blog entries of a given user.
book_help in modules/book.module
Implementation of hook_help().
comment_configure in modules/comment.module
Menu callback; presents the comment settings page.
comment_help in modules/comment.module
Implementation of hook_help().
comment_render in modules/comment.module
contact_mail_user in modules/contact.module
contact_user in modules/contact.module
Implementation of hook_user().
drupal_goto in includes/common.inc
Send the user to a different Drupal page.
drupal_help in modules/drupal.module
Implementation of hook_help().
drupal_settings in modules/drupal.module
Implementation of hook_settings().
file_create_url in includes/file.inc
Create the download path to a file.
filter_help in modules/filter.module
Implementation of hook_help().
forum_overview in modules/forum.module
Returns an overview list of existing forums and containers
help_links_as_list in modules/help.module
help_main in modules/help.module
Menu callback; prints a page listing a glossary of Drupal terminology.
hook_nodeapi in developer/hooks/core.php
Act on nodes defined by other modules.
hook_ping in developer/hooks/core.php
Ping another server.
hook_search in developer/hooks/core.php
Define a custom search routine.
l in includes/common.inc
Format an internal Drupal link.
locale_help in modules/locale.module
Implementation of hook_help().
menu_get_active_help in includes/menu.inc
Returns the help associated with the active menu item.
node_admin in modules/node.module
Menu callback; presents the content administration overview.
node_admin_nodes in modules/node.module
Generate the content administration overview.
node_block in modules/node.module
Implementation of hook_block().
node_feed in modules/node.module
A generic function for generating RSS feeds from a set of nodes.
node_help in modules/node.module
Implementation of hook_help().
node_page_default in modules/node.module
Generate a listing of promoted nodes.
node_search in modules/node.module
Implementation of hook_search().
pager_link in includes/pager.inc
Format a link to a specific query result page.
poll_help in modules/poll.module
Implementation of hook_help().
poll_view_voting in modules/poll.module
Generates the voting form for a poll.
queue_nodeapi in modules/queue.module
Implementation of hook_nodeapi().
search_form in modules/search.module
Render a search form.
statistics_access_log in modules/statistics.module
statistics_help in modules/statistics.module
Implementation of hook_help().
system_help in modules/system.module
Implementation of hook_help().
system_view_general in modules/system.module
taxonomy_form_term in modules/taxonomy.module
taxonomy_form_vocabulary in modules/taxonomy.module
taxonomy_help in modules/taxonomy.module
Implementation of hook_help().
taxonomy_rss_item in modules/taxonomy.module
Provides category information for rss feeds
taxonomy_term_page in modules/taxonomy.module
Menu callback; displays all nodes associated with a term.
theme_comment_form in modules/comment.module
theme_comment_post_forbidden in modules/comment.module
theme_forum_display in modules/forum.module
Format the forum body.
upload_help in modules/upload.module
Implementation of hook_help().
upload_nodeapi in modules/upload.module
Implementation of hook_nodeapi().
user_admin in modules/user.module
user_block in modules/user.module
Implementation of hook_block().
user_help in modules/user.module
Implementation of hook_help().
user_login in modules/user.module
user_pass in modules/user.module
user_register in modules/user.module
user_search in modules/user.module
Implementation of hook_search().
xtemplate_node in themes/engines/xtemplate/xtemplate.engine
xtemplate_page in themes/engines/xtemplate/xtemplate.engine
_blogapi_get_post in modules/blogapi.module
_locale_add_language in includes/locale.inc
Helper function to add a language
_locale_admin_import_screen in includes/locale.inc
User interface for the translation import screen
_locale_admin_manage_screen in includes/locale.inc
User interface for the language management screen
_locale_string_seek_form in includes/locale.inc
User interface for the string search screen

Code

includes/common.inc, line 1462

<?php
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;
      }
    }
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.