I'm using node_load to get the content of a node displayed in my module.
Now I like to modify the text from the node with some values from variables.

How can I do that?

Any ideas?

I appreciate your help.
Ingo

Comments

william_frane’s picture

If you want to modify the (body) text of the node, you need to change the value of the body variable in the node object.

For example:

// Loading the node.
$node = node_load(12345);

// An example variable.
$a_variable = 'Sasquatch';

// Changing the body of the node.
$node->body = "The body of this node has been replaced with this text and the word $a_variable.";

// Saving the node.
node_validate($node);
if ($errors = form_get_errors()){
		print_r($errors);
}
$node_to_save = node_submit($node);
node_save($node_to_save);

Hope that helps.