Updating a field programmatically, hook_node_update
Entity metadata wrappers

The entity API provides some wrapper classes you may use to easily deal with entities and to leverage the entity property information modules provided. With the help of the wrappers you can access the property information, loop over known properties, or just get/set the described data values, etc.

These are some simple usage examples as found in the README:

For making use of this information (metadata) the module provides some
wrapper classes which ease getting and setting values. The wrapper supports
chained usage for retrieving wrappers of entity properties, e.g. to get a
node author's mail address one could use:

$wrapper = entity_metadata_wrapper('node', $node);
$wrapper-&gt;author-&gt;mail-&gt;value();


To update the user's mail address one could use

$wrapper-&gt;author-&gt;mail-&gt;set('sepp@example.com');


or

$wrapper-&gt;author-&gt;mail = 'sepp@example.com';


The wrappers always return the data as described in the property
information, which may be retrieved directly via entity_get_property_info()
or from the wrapper:

$mail_info = $wrapper-&gt;author-&gt;mail-&gt;info();


In order to force getting a textual value sanitized for output one can use,
    e.g.

$wrapper-&gt;title-&gt;value(array('sanitize' =&gt; TRUE));


to get the sanitized node title. When a property is already returned
sanitized by default, like the node body, one possibly wants to get the
not-sanitized data as it would appear in a browser for other use-cases.
To do so one can enable the 'decode' option, which ensures for any sanitized
data the tags are stripped and HTML entities are decoded before the property
is returned:

$wrapper-&gt;body-&gt;value-&gt;value(array('decode' =&gt; TRUE));


That way one always gets the data as shown to the user. However if you
really want to get the raw, unprocessed value, even for sanitized textual
data, you can do so via:

$wrapper-&gt;body-&gt;value-&gt;raw();


More examples:

$wrapper-&gt;body-&gt;set(array('value' =&gt; "content"));
$wrapper-&gt;field_text[0] = 'the text';
$wrapper-&gt;field_text[0]-&gt;set(array('value' =&gt; "content"));
$wrapper-&gt;field_text2-&gt;summary = 'the summary';
$wrapper-&gt;field_text2-&gt;value = 'the text';

$wrapper-&gt;save();
$wrapper-&gt;delete();


More docs: http://drupal.org/node/1021556