P
P
prodavec macdonalds2015-06-11 03:37:42
PHP
prodavec macdonalds, 2015-06-11 03:37:42

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

2 answer(s)
U
UksusoFF, 2015-06-11
@prodavecmacdonalds

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);
}
?>

Then, or scanner 'om, replace the ones that are already there.
Or resave all articles via VBO , then the hook above will work.

X
xmoonlight, 2015-06-11
@xmoonlight

regexp

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question