Altering body text of a node before the page is rendered I am using the Zen theme. I want to alter the body text before it is rendered as a page. In particular, I want to replace a string with another string. I thought that the general solution for this would be to place the code in the the theme_preprocess_node hook in my sub-theme's template.php. Here is the code that I've got so far:

&lt;?php
function mytheme_preprocess_node(&amp;$variables) {
    if ((isset($variables['body'][0]['value'])) &amp;&amp; (preg_match('/suppose/i', $variables['body'][0]['value']))) {
        dpm('string was found in "value"');
        $variables['body'][0]['value'] = preg_replace('/suppose/i', 'new tring', $variables['body'][0]['value']);
    }
    if ((isset($variables['body'][0]['safe_value'])) &amp;&amp; (preg_match('/suppose/i', $variables['body'][0]['safe_value']))) {
        dpm('string was found in "safe_value"');
        $variables['body'][0]['safe_value'] = preg_replace('/suppose/i', 'new tring', $variables['body'][0]['safe_value']);
    }        
}
?&gt;


However, this has no effect what so ever. I do get a positive match - this I can verify by the debug dpm() display.

Am I simply trying to rewrite the wrong sub-array?

Thanks in advance,
Valera Rozuvan
Try this in mytheme_preprocess_node:

function mytheme_preprocess_node(&amp;$vars) { 
  // Collect / create / adjust new body content
  $new_body = 'xyz';
  // Assign to output
  $vars['content']['body'][0]['#markup'] = $new_body
}


After looking through the vars array a bit, I'm a little surprised at the amount of redundant data there.  There are a few different places where the body text is recorded, usually as an array.  

Note that the node body will likely have a 'safe value' and a 'value'.  You'll probably want to use safe almost all the time, but it might be good to check on the filter type selected in $vars['body'][0]['format'] to select which of the body values you'll want to output and display.