How to define a function in drupal core How should I define a function in the core of drupal 7 that I can use the function in the blocks, pages and etc?
Simple answer - don't :)

You shouldn't change anything in the core files, it'll just make things difficult when you try to update.

Drupal's way of extending functionality is through Modules; it's easy to write your own.

When a module is enabled, all the functions defined in the 'MODULENAME.module' file are available during the page build. So if you define a function

function MYMODULE_say_hello() {
  return 'Hi!';
}


That will be available for use in code in the same module, other modules and themes. 

As Drupal doesn't currently use namespaces, it's important to prefix your 'global' function names with the name of the module. This just helps to make sure you avoid collisions with other functions of the same name (imagine another module also wanted to say_hello()), which would otherwise result in a fatal error.

There's also a convention in Drupal programming to prefix 'private' function names (those that should only be used internally by your module), with an underscore, e.g.

function _MYMODULE_say_hello_quietly() {
  return '&lt;hush&gt;Hi&lt;/hush&gt;';
}


This doesn't technically stop them from being available to other modules (which is actually a good thing in a lot of cases), but it's a good pattern to fall into for Drupal 6/7 development.

For Drupal 8, thankfully, we'll have a much more OO focused core. But that's a topic for another day...