PHP正则表达式删除重复的子标记但保留父级和内容

I'm quite poor in regular expression,it would be a big time saver if I could get your help.

Are there any way to use preg_replace to return the output from input below:

input

w1 <strong>w2</strong> w3 w4 <strong><strong>w5 <strong>w6</strong></strong></strong> w7

output

w1 <strong>w2</strong> w3 w4 <strong>w5 w6</strong> w7

My purpose is to eliminate all duplicate inner child tag but keep the parent and its content. Both resulted in html rendered like this (so I'm trying to make the tag cleaner):

w1 w2 w3 w4 w5 w6 w7

w1 w2 w3 w4 w5 w6 w7

Your help would be greatly appreciated.

Try this:

$str = 'w1 <strong>w2</strong> w3 w4 <strong><strong>w5 <strong>w6</strong></strong></strong> w7';
$filtered_array = preg_replace('/(\<[a-zA-Z\/]+\>)+/', '$1', $str);

This will match and replace child HTML tags.

Worked with the solution from @HamZa

function remove_duplicate_child_tag($input, $tag = 'strong'){

    $pattern = "~
<{$tag}\s*>                         # Match strong open tag
(                                   # Open group 1
    (?:                             # Non-capturing group
        (?:(?!</?strong\s*>).)      # Match anything that not strong tag (open/close)
        |                           # Or
        (?R)                        # Repeat the whole pattern
    )*                              # Repeat the non-capturing group zero or more times
)                                   # Close group 1
</{$tag}\s*>                        # Match strong close tag
~xs";

    $output = preg_replace_callback($pattern, function($m, $tag = 'strong'){
        return "<{$tag}>" . preg_replace("~</?{$tag}\s*>~", '', $m[1]) . "</{$tag}>";
    }, $input);

    return $output;
}