How can I access the node ID when writing PHP into a block?
You can use the menu_get_object() function which will get you the node object for the page, assuming of course your block is being displayed on a node page:

$node = menu_get_object();

if (isset($node-&gt;nid)) {
  $nid = $node-&gt;nid;
  echo my_custom_function($nid, $my_desired_class);
}