I have this code HTML:
<div class="wrap">
<div class="wp-checkbox" data-value="zf">content</div>
<div class="wp-checkbox" data-value="tdp">content</div>
</div>
I would like to replace the content of these divs, but each differently.
I tried to do it by code:
$pattern = '/=\"zf\">.*<\/div>/';
$pattern2 = '/=\"tdp\">.*<\/div>/';
$html = preg_replace( $pattern, '="zf">new content of div</div>', $html );
$html = preg_replace( $pattern2, '="tdp">new content of another div</div>', $html );
But there is a problem that this code - it replaced all my divs and I get this:
<div class="wrap">
<div class="wp-checkbox" data-value="zf">new content of div</div>
</div>
How can I change these divs one by one? How can I show in the pattern that I want to change only until the first closing </div>
(not to last one)?
I would like to get this result:
<div class="wrap">
<div class="wp-checkbox" data-value="zf">new content of div</div>
<div class="wp-checkbox" data-value="tdp">new content of div</div>
</div>
Thank you in advance for help.