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); }
Output for 7.0.0 - 7.0.25, 7.1.0 - 7.1.20, 7.2.6 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
<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>

preferences:
115.85 ms | 404 KiB | 182 Q