How to update a field programmatically and keep the fields format and array structure? I'm trying to update a field with the format full_html. But when I'm updating the field, all the html tags will disappear and the old text is still there in the safe_value. So how can I update the the text in field and keep the existing structure and the html-tags?

I have tried this:

$node = $node_load($my_node_id);
$node-&gt;body['und'][0]['value'] = 'My new text.';


My field before editing

[body] =&gt; Array
    (
        [und] =&gt; Array
            (
                [0] =&gt; Array
                    (
                        [value] =&gt; &lt;p&gt;My old text.&lt;/p&gt;
                        [summary] =&gt; 
                        [format] =&gt; full_html
                        [safe_value] =&gt; &lt;p&gt;My old text.&lt;/p&gt;

                        [safe_summary] =&gt; 
                    )

            )

    )


My field after editing

[body] =&gt; Array
    (
        [und] =&gt; Array
            (
                [0] =&gt; Array
                    (
                        [value] =&gt; My new text. //All the html-tags are removed
                        [summary] =&gt; 
                        [format] =&gt; full_html
                        [safe_value] =&gt; &lt;p&gt;My old text.&lt;/p&gt; //The old text is still there

                        [safe_summary] =&gt; 
                    )

            )

    )
Calling node_save() won't automatically re-load the node so you'll need to do it manually if you want to see the computed field values:

$node = node_load($my_node_id);
$node-&gt;body['und'][0]['value'] = 'My new text.';

node_save($node);

// Re-load the node from the db
$node = node_load($node-&gt;nid, NULL, TRUE);

// $node-&gt;body now has the values you would expect.


I just tried that and can confirm I get the same behaviour as you (the safe_value is not updated) if the call to node_load() is commented out.