How do I get the node ID from the URL? So far, I came across these 3 functions in Drupal 7, but I am not really sure what the difference between them is, and which is more appropriated to get the node ID in a block preprocess function.


menu_get_object()  
menu_get_item()  
drupal_lookup_path()


Can you give me any insight?
I am not really sure what the difference between them is



menu_get_object() returns the object associated with the page currently shown. If the code is executed when Drupal is showing the page example.com/node/1, then menu_get_object() will return the node object for the node whose ID is 1; if the page being shown is example.com/user/1, then menu_get_object('user') will return the user object for the user whose ID is 1.  
menu_get_item() returns an array containing an index for each field contained in the "menu_router" table. This includes:


path: the current path of the menu callback
load_functions: an array of function names (like node_load) to be called to load an object corresponding to a part of the current path
access_callback: the callback that checks if the currently logged in user has access to the menu item
page_callback: the name of the function that renders the page
title: the title for the page associated to the menu item

drupal_lookup_path() is the function that returns you the internal path associated with the alias passed as argument. If "homepage" is the alias associated to example.com/node/1, then drupal_lookup_path("homepage") will return "node/1". Path aliases can be associated to any internal paths, not only to node paths.



  and which is more appropriated to get the node ID in a block preprocess function.


If all you want to get is the node ID of the node currently shown, then you just need to use the following code:

if (arg(0) == 'node') {
  $nid = arg(1);
}


If you need to get the node object, then you can use the following code:

if ($node = menu_get_object()) {
  // Use the node object.
}


Of those snippets, the second is better, as it returns the correct node object for internal paths such as node/1/revisions/3/view.

Keep in mind that some preprocess functions, such as the ones for the page, or the node, have already a $variables['node']. This means that in those cases, you just need to use the following snippet in your preprocess function, without worrying about which function to use.

if (isset($variables['node'])) {
  // Check the node ID or other properties.
}


For other preprocess functions, check the documentation to see if there is any variable containing the node object. For example, that is the case for template_preprocess_comment() which makes $variables['node'] available to the preprocess functions for comments.