3v4l.org

run code in 300+ PHP versions simultaneously
<?php $source = '<p>Today, not only we have so many breeds that are trained this and that.</p> <h4><strong>We must add a dot after the closing strong</strong></h4> <p>Hunting with your dog is a blah blah with each other.</p> <h2>No need to change this one!</h2> <p>Hunting with your dog is a blah blah with each other.</p>'; $source = addMissingPunctuation( $source ); echo $source; function addMissingPunctuation( $input ) { return preg_replace("/[^,.;!?]\K<\/h[1-6]>/mi", '.\0', $input); }

preferences:
35.48 ms | 404 KiB | 5 Q