This is the Drupal way for removing markup returned from a field that has markup. In this example I am removing the markup from the term description field.
use Drupal\Component\Render\PlainTextOutput;
$description = trim(PlainTextOutput::renderFromHtml($term->getDescription()));