The search for the closing tag does not have to start from the beginning of the string. It makes more sense an dis more efficient to start searching AFTER the opening tag. This also allows to search for tags that do have a distinct opening tag and a generic closing tag (e.g. Dreamweaver editable regions. I would suggest changing
$mytext = substr($string,$start,intval(strpos($string,$ct) - $start));
$mytext = substr($string,$start,intval(strpos($string,$ct,$start) - $start));
which uses the position of the opening tag as an offset for finding the closing tag.