- Output for 5.4.29, 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
- <tag></tag>
<?php
$string = "<tag>i dont know what is here</tag> don't remove this text";
$string = preg_replace('|^<([a-z]*).*|', '<$1></$1>', $string);
echo $string; // <tag></tag>