I am new using regex expression. After much digging I came up with this code. I would like to know if this is the correct way. I want to search in Joomla for some html tags with specific class and then replace the code between those tags. I want to use an array ($patterns) with tag and classes and another array ($replacements) with replacements values.
$body = JResponse::getBody();
$patterns = array
(
array('a','logo')
array('span','main')
);
$replacements = array
(
array('<p>some text</p>')
array('<p>another text</p>')
);
foreach ($patterns as $key => $value) {
$body = preg_replace('/(<'.$patterns[$key][0].' .*?class=".*?'.$patterns[$key][1].'.*?">)(.*?)(<\/'.$patterns[$key][0].'>)/', '$1'.$replacements[$key][0].'$3', $body);
}