Answer the question
In order to leave comments, you need to log in
How to programmatically replace the tag in the field (body) of the material?
There is a material with a field (body) editable in CCK, respectively, it can contain a title wrapped in an h2 tag. It is necessary to replace h2 with another tag, for example span, so as not to interfere with the robot. Doing it by hand is not an option (not only are there a lot of materials, but headings are needed in the form in which they are present at the moment)
Answer the question
In order to leave comments, you need to log in
To prevent the following tags from appearing in new materials:
<?php
function MODULE_NAME_node_presave($node) {
$regex = '#<h[1-6]>(.*?)</h[1-6]>#s';
$replace = '<span class="headers">$1</span>';
$body = &$node->body['und'][0]['value'];
$body = preg_replace($regex, $replace, $body);
}
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question