Replacing a certain character pattern in a textfield when saving an entity I got an entity type containing a long text field. If a user types in a certain character pattern ("xX" for example), this string "xX" should replaced with "×" (the proper symbol for multiplication) after saving the entity.
I looked at hook_field_presave and hook_field_attach_presave but don't know how to use correctly.

This is the code i tried in a custom module:

function replace_multiplication_symbol_field_presave($entity_type, $entity, $field, $instance, $langcode, &amp;$items) {
  if ($field['name'] == 'field_technical_description') {
    foreach ($items as $delta =&gt; $item) {
      if (isset($item['value'])) {
        $items[$delta]['value'] = str_replace('xX', '&amp;times;', $items[$delta]['value']);;
      }
    }
  }
}
So, hook_field_presave, according to the documentation, "Defines custom presave behavior for this module's field types." So unless your defining a field type in your module, this is the wrong hook to use.

Instead, your gonna want to use hook_field_attach_presave. $entity_type will contain the type of entity the save is being called from (node, user, etc). $entity is the full entity object, which you can just go ahead and edit. 

For example, a very basic function like so:

function replace_multiplication_symbol_field_attach_presave($entity_type, $entity){
  if(!empty($entity-&gt;field_field_technical_description['und'][0]['value'])){
  $entity-&gt;field_field_technical_description['und'][0]['value'] = "test";
  }
}


would, whenever an enity is save, check for the field field_field_technical_description and switch it's value to "test," if it's value was not null.